#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct node {
  int to, next;
};
node edge[N * 2];
int graph[N], tot;
void addedge(int i, int x, int y) {
  edge[i].to = y;
  edge[i].next = graph[x];
  graph[x] = i;
}
int dp[N], ans;
int fa[N];
int n, m;
void dfs(int x) {
  int i, y;
  dp[x] = 1;
  for (i = graph[x]; i; i = edge[i].next) {
    y = edge[i].to;
    if (y == fa[x]) continue;
    fa[y] = x;
    dfs(y);
    dp[x] -= dp[y];
    ans += abs(dp[y]);
  }
}
int main() {
  int i, x, y;
  scanf("%d%d", &n, &m);
  if (m != n - 1) {
    return 0;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    tot++;
    addedge(tot, x, y);
    tot++;
    addedge(tot, y, x);
  }
  dfs(1);
  if (dp[1])
    printf("-1\n");
  else
    printf("%d", ans);
}
