#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long ans;
long long tmp;
signed main() {
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long a, b;
    cin >> a >> b;
    ans += b;
    tmp += a * b;
    tmp %= n;
  }
  if (ans < n) {
    cout << "1\n";
  } else if (ans > n) {
    cout << "-1\n";
  } else {
    if (tmp == ((1 + n) * n / 2) % n) {
      cout << "1\n";
    } else {
      cout << "-1\n";
    }
  }
}
