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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
    int n, m; in >> n >> m;
    assert(n == (m+1));

    vector<int> adj[101010];
    REP(i, m)
    {
        int x, y; in >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    int papa[101010]; memset(papa, -1, sizeof(papa));
    int lvl[101010];
    queue<int> Q;
    Q.push(1);
    lvl[1] = 0;
    papa[1] = 1;

    vector<int> v;
    while(Q.size())
    {
        int t = Q.front(); Q.pop();
        for(there : adj[t])
        {
            if(papa[there] != -1) continue;

            papa[there] = t;
            lvl[there] = lvl[t]+1;
            v.pb(there);

            Q.push(there);
        }
    }

    int state[101010]; memset(state, 0, sizeof(state));
    int res = 0;
    for(int i=v.size()-1; i>=0; i--)
    {
        if(state[v[i]]) continue;
        else
        {
            state[v[i]] = 1;
            state[papa[v[i]]] ^= 1;
            res++;
        }
    }

    bool flag = true;
    REPE(i,1, n) if(state[i] == 0) flag = false;

    if(flag) out << res << "\n";
    else out << "-1\n";

    return 0;
}
