#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
const int inf = 1e9+7;

int n, m, f[N][2];
vector<int> g[N];

void dfs(int v, int pr = -1) {
    f[v][0] = 0;
    f[v][1] = inf;
    for (auto& to : g[v]) {
        if (to == pr) continue;
        dfs(to, v);
        int b[2] = {f[v][0], f[v][1]};
        f[v][0] = f[v][1] = inf;
            f[v][1] = min(f[v][1], b[0] + f[to][0] + 1);
            f[v][1] = min(f[v][1], b[1] + f[to][1]);
            f[v][0] = min(f[v][0], b[0] + f[to][1]);
        }
    }
}

int main() {
    scanf("%d %d", &n, &m);
    if (n == m) {
        return 0;
    }
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    cout << (f[0][1] == inf ? -1 : f[0][1]) << endl;
    return 0;
}
