#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, E;
int fir[N], nex[N << 1], arr[N << 1];
inline void Add_Edge(int x, int y) {
  nex[++E] = fir[x];
  fir[x] = E;
  arr[E] = y;
}
namespace Subtask1 {
int dp[N], sum = 0;
void dfs(int x, int dep, int fa) {
  dp[x] = (dep & 1) ? 1 : -1;
  for (int i = fir[x]; i; i = nex[i]) {
    if (arr[i] == fa) continue;
    dfs(arr[i], dep + 1, x);
    dp[x] += dp[arr[i]];
  }
  sum += abs(dp[x]);
}
void main() {
  dfs(1, 1, 0);
  if (dp[1] != 0)
    puts("-1");
  else
    printf("%d\n", sum);
}
}  // namespace Subtask1
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    Add_Edge(x, y);
    Add_Edge(y, x);
  }
  if (m == n - 1) Subtask1::main();
}
