#include <bits/stdc++.h>
using namespace std;
const int MM = 1000000007;
const int MX = 100005;
vector<int> T[MX];
long long G[MX], cnt[MX];
int N, M;
void dfs(int x, int lv = 0, int p = -1) {
  if (lv & 1)
    cnt[x] = 1;
  else
    cnt[x] = -1;
  for (int c : T[x]) {
    if (c == p) continue;
    dfs(c, lv + 1, x);
    cnt[x] += cnt[c];
    G[x] += G[c];
  }
  G[x] += abs(cnt[x]);
}
int main() {
  scanf("%d%d", &N, &M);
  if (N == M) return 0;
  for (int i = 1; i <= M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    T[a].push_back(b);
    T[b].push_back(a);
  }
  dfs(1);
  if (cnt[1] != 0)
    printf("-1\n");
  else
    printf("%lld\n", G[1]);
}
