#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (M); ++i) {
    int n, m;
    cin >> n >> m;
    s[i] = n, c[i] = m;
  }
  for (int i = 0; i < (M); ++i) {
    if (s[i] < 1 || 3 < s[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
