#include <bits/stdc++.h>
using namespace std;
const int N = 201010;
vector<int> e[N];
int deep[N], odd[N], even[N];
long long sum[N];
int n, m, i, a, b;
void dfs(int x, int fa) {
  int i;
  deep[x] = deep[fa] + 1;
  if (deep[x] & 1)
    odd[x]++;
  else
    even[x]++;
  for (i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) {
      dfs(e[x][i], x);
      odd[x] += odd[e[x][i]];
      even[x] += even[e[x][i]];
      sum[x] += sum[e[x][i]] + abs(odd[e[x][i]] - even[e[x][i]]);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  if (n % 2 == 1) {
    printf("-1");
    return 0;
  }
  dfs(1, 0);
  if (abs(odd[1] - even[1]))
    printf("-1\n");
  else
    printf("%d\n", sum[1]);
}
