#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 1e8 + 7;
const double eps = 1e-6;
int main() {
  long long n;
  int k;
  cin >> n >> k;
  long long s = n * (n - 1) / 2;
  s %= n;
  long long t = 0;
  long long cnt = 0;
  for (int i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    (t += a * b) %= n;
    cnt += b;
  }
  if (cnt < n) {
    cout << "1\n";
  } else if (cnt > n) {
    cout << "-1\n";
  } else {
    if (s == t) {
      cout << "1\n";
    } else {
      cout << "-1\n";
    }
  }
}
