#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m;
vector<int> G[N];
int f[N], rem[N];
void DFS(int o, int fa = 0) {
  rem[o] = 1;
  for (int v : G[o]) {
    if (v == fa) continue;
    DFS(v, o);
    f[o] += f[v] + abs(rem[v]);
    rem[o] -= rem[v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v), G[v].push_back(u);
  }
  DFS(1);
  if (!rem[1])
    printf("%d\n", f[1]);
  else
    puts("-1");
  return 0;
}
