#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[200002], b[200002];
long long sum;
long long allStone;
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
    sum += a[i] * b[i];
    sum %= n;
    allStone += b[i];
    if (allStone > n) {
      printf("-1");
      return 0;
    }
  }
  if (allStone < n) {
    printf("1");
    return 0;
  }
  if (sum == (n * (n + 1) / 2) % n)
    printf("1");
  else
    printf("-1");
}
