#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  long long sum = 0, inv = 0;
  for (long long i = 1; i <= k; ++i) {
    long long a, b;
    cin >> a >> b;
    sum += b;
    inv += a * b;
    inv %= n;
  }
  if (sum < n) {
    cout << 1 << '\n';
  } else if (sum == n) {
    if (inv % n == (n * (n + 1) / 2) % n)
      cout << 1 << '\n';
    else
      cout << -1 << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
