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