#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int INF = 1e9;
long long int s = 32768;
struct node {
  int l = -1, r = -1;
  int z = 0, o = 0;
};
long long int po(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b % 2 == 1) {
      re = (re * a);
      re %= mod;
    }
    a = (a * a);
    a %= mod;
    b >>= 1;
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  while (test--) {
    long long int n, k;
    cin >> n >> k;
    pair<long long int, long long int> a[k];
    long long int t = 0;
    for (long long int i = (0); i < (k); i++) {
      cin >> a[i].first >> a[i].second;
      t += a[i].second;
    }
    long long int o = (n * (n + 1)) / 2;
    if (t < n) {
      cout << 1;
    } else if (t > n) {
      cout << -1;
    } else {
      for (long long int i = (0); i < (k); i++) {
        o -= a[i].first * a[i].second;
      }
      o += n * n;
      if (o % n == 0) {
        cout << 1;
      } else
        cout << -1;
    }
  }
  return 0;
}
