#include <bits/stdc++.h>
template <class T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
using namespace std;
const int N = 1e5 + 5;
struct eg {
  int v, nx;
} e[N << 1];
int head[N], tot;
inline void add(register int u, register int v) {
  e[++tot] = {v, head[u]}, head[u] = tot;
}
int d[N], n, m, res;
void dfs(int u, int fa) {
  for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
    if (v != fa) {
      dfs(v, u);
      if (!d[v]) d[u] ^= 1, ++res;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1, u, v; i <= m; ++i) scanf("%d%d", &u, &v), add(u, v);
  dfs(1, 0);
  res = (!d[1] ? -1 : res);
  printf("%d\n", res);
  return 0;
}
