#include <bits/stdc++.h>
using namespace std;
const int N = 201010;
vector<int> e[N];
int deep[N], odd[N], even[N];
long long sodd[N], seven[N];
int n, m, i, a, b;
void dfs(int x, int fa) {
  int i;
  deep[x] = deep[fa] + 1;
  for (i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) {
      dfs(e[x][i], x);
      odd[x] += odd[e[x][i]];
      sodd[x] += sodd[e[x][i]];
      even[x] += even[e[x][i]];
      seven[x] += seven[e[x][i]];
    }
  if (odd[x]) sodd[x] += odd[x] * 2 - 1;
  if (even[x]) seven[x] += even[x] * 2 - 1;
  if (odd[x] + even[x]) {
    int tmp = min(odd[x], even[x]);
    odd[x] -= tmp;
    even[x] -= tmp;
    if (tmp) sodd[x] -= tmp + tmp - 1;
  } else {
    if (deep[x] % 2 == 1)
      odd[x]++, sodd[x] += 1;
    else
      even[x]++, seven[x] += 1;
  }
}
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 ((odd[1] <= 1) && (even[1] <= 1)) {
    printf("%I64d\n", (seven[1] + sodd[1]) / 2);
  } else
    printf("-1\n");
}
