#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  long long n, k;
  cin >> n >> k;
  long long sum = 0, tot = 0;
  for (long long i = 0; i < k; ++i) {
    long long pos, cnt;
    cin >> pos >> cnt;
    pos--;
    sum += pos * cnt;
    tot += cnt;
  }
  long long want = n * (n - 1) / 2;
  if (tot < n) {
    cout << 1 << '\n';
  } else if (tot > n) {
    cout << -1 << '\n';
  } else if (sum % n == want % n) {
    cout << 1 << '\n';
  } else {
    cout << -1 << '\n';
  }
}
