//#pragma GCC optimize("O3,unroll-loops,inline")

#include <bits/allocator.h>

//#pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using ull = unsigned long long;

struct segtree {
    vector<int> tr;
    int n;
    segtree(int n) : n(n), tr(2 * n) {}
    void upd(int i, int x) {
        for (tr[i += n] = x; i >= 0; tr[i >>= 1] = max(tr[i], tr[i ^ 1]));
    }
    int get(int l, int r) {
        int ans = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1)
                ans = max(ans, tr[l++]);
            if (~r & 1)
                ans = max(ans, tr[r--]);
        }
        return ans;
    }
};

struct fenwick {
    vector<int> t;
    int n;
    fenwick(int n) : n(n), t(n + 1) {}
    void upd(int i, int x) {
        for (++i; i <= n; i += i & -i) t[i] += x;
    }
    int get(int i) {
        int x = 0;
        for (++i; i > 0; i -= i & -i) x += t[i];
        return x;
    }
};

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

mt19937 rnd(228);

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> gr(n);
    for (int i = 0, u, v; i < n; ++i) {
        cin >> u >> v;
        --u, --v;
        gr[u].push_back(v);
        gr[v].push_back(u);
    }
    vector<bool> used(n, false);
    int sz = 0;
    auto dfs = [&](auto self, int v) -> void {
        if (used[v])
            return;
        ++sz;
        used[v] = 1;
        for (int u : gr[v])
            self(self, u);
    };
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        sz = 0;
        dfs(dfs, i);
        if (sz > 0)
            ans += sz - 1;
    }
    cout << m - ans << '\n' << -1;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
//     cin >> t;
    while (t--) solve();
//    cerr << fixed << setprecision(10) << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
}
