#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = (int) 1e5 + 100;
vector <int> g[N];


int eA, eB;

int ans;

int color[N];
int val[N];

vector <int> st;

bool dfsXs(int v, int par, int k)
{
    st.push_back(val[v] * k);
    if (v == eB)
        return true;
    for (int to : g[v])
    {
        if (to == par)
            continue;
        if (min(v, to) == eA && max(v, to) == eB)
            continue;
        if (dfsXs(to, v, -k))
            return true;
    }
    st.pop_back();
    return false;
}

void dfsColor(int v, int par, int c)
{
    color[v] = c;
    for (int to : g[v])
    {
        if (to == par)
            continue;
        if (color[to] != 0)
        {
            eA = min(v, to);
            eB = max(v, to);
            continue;
        }
        dfsColor(to, v, c ^ 3);
    }
}

int solve(int v, int par)
{
    int &x = val[v];
    for (int to : g[v])
    {
        if (to == par)
            continue;
        if (min(v, to) == eA && max(v, to) == eB)
            continue;
        x += solve(to, v);
    }
    ans += abs(x);
    return -x;
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, m;
    scanf("%d%d", &n, &m);
    
    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    memset(val, -1, sizeof val);

    if (m == n)
    {
        dfsColor(0, 0, 1);
        //eprintf("eA = %d, eB = %d\n", eA, eB);
        //for (int i = 0; i < 3; i++)
        //    eprintf("%d ", color[i]); eprintf("\n");
        if (color[eA] == color[eB]) // odd
        {
            int cnt[3] = {0, 0, 0};
            for (int i = 0; i < n; i++)
            {
                cnt[color[i]]++;
            }
            int x = (cnt[color[eA]] - cnt[color[eA] ^ 3]) / 2;
            //eprintf("x = %d\n", x);
            val[eA] += x;
            val[eB] += x;
            ans += abs(x);
            
            if (solve(0, 0) != 0)
            {
                printf("-1\n");
                return 0;
            }
        }
        else
        {
            if (solve(eA, eA) != 0)
            {
                printf("-1\n");
                return 0;
            }
            dfsXs(eA, eA, 1);
            st.erase(st.begin());
            sort(st.begin(), st.end());
            int x = st[(int) st.size() / 2];
            eprintf("x = %d\n", x);
            ans += abs(x);
            for (int z : st)
            {
                eprintf("%d(%d) ", z - x, z);
                ans += abs(z - x) - abs(z);
            }
            eprintf("\n");
        }
    }
    else
    {
        if (solve(0, 0) != 0)
        {
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n", ans);

	return 0;
}




Measured memory_bytes: 14840