#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, m, a[MAXN], b[MAXN], d[MAXN];
struct node {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], top = 0;
inline void push(int i, int j) {
  edge[++top] = (node){j, head[i]}, head[i] = top;
}
int vis[MAXN], cur[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  assert(m == n - 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    push(a[i], b[i]);
    push(b[i], a[i]);
    d[a[i]]++, d[b[i]]++;
  }
  static int stk[MAXN], stk_top = 0;
  for (int i = 1; i <= n; i++) {
    cur[i] = 1;
    if (d[i] == 1) {
      vis[i] = 1;
      stk[++stk_top] = i;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n - 2; i++) {
    int nd = stk[stk_top--];
    cnt += cur[nd];
    for (int i = head[nd]; i; i = edge[i].next) {
      int to = edge[i].to;
      if (vis[to]) continue;
      if (cur[nd]) cur[to] ^= 1;
      if ((--d[to]) == 1) {
        vis[to] = 1;
        stk[++stk_top] = to;
      }
    }
  }
  if (cur[stk[1]] == cur[stk[2]])
    cout << cnt + cur[stk[1]] << endl;
  else
    puts("-1");
  return 0;
}
