#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
vector<int> E[100005];
int B[100005];
bool used[100005];
int cnt[2];
long long sumDiff;
void dfs(int x, int h = 0) {
  cnt[h & 1]++;
  B[x] = (h & 1) ? 1 : -1;
  used[x] = true;
  for (int y : E[x]) {
    if (used[y]) continue;
    dfs(y, x);
    sumDiff += abs(B[y]);
    B[x] += B[y];
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[a].push_back(b);
    E[b].push_back(a);
  }
  dfs(1);
  printf("%lld\n", cnt[0] != cnt[1] ? -1 : sumDiff);
}
