#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  long long sum = 0;
  int ret = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    ret = (ret + 1LL * x * y) % n;
    sum += y;
  }
  int need = 1LL * n * (n - 1) / 2 % n;
  if (sum > n || sum == n && ret != need) {
    cout << -1 << '\n';
  } else {
    cout << 1 << '\n';
  }
  return 0;
}
