#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int n, m;
int len[MAX_N];
vector<int> G[MAX_N];
bool dfsTree(int v = 0, int p = 0) {
  len[v] = 1;
  int fard = 0;
  for (int u : G[v])
    if (u != p) {
      if (!dfsTree(u, v)) return false;
      len[v] += len[u];
      fard += len[u] & 1;
    }
  fard += (n - len[v]) & 1;
  return fard <= 1;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  if (n & 1) {
    cout << "-1\n";
    return 0;
  }
  if (n - 1 == m) {
    cout << "-1\n";
    return 0;
  }
  assert(false);
  return 0;
}
