#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> data(2, vector<int>(m));
  for (int i = 0; i < m; i++) {
    cin >> data.at(i).at(0) >> data.at(i).at(1);
  }
  for (int i = 0; i < m; i++) {
    if (n = 3 && data.at(i).at(0) == 1 && data.at(i).at(0) == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n = 2 && data.at(i).at(0) == 2 && data.at(i).at(0) == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int j = 0; j < m; j++) {
      if (data.at(i).at(0) == data.at(j).at(0) &&
          data.at(i).at(1) != data.at(j).at(1)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
}
