#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int main() {
  long long n, k, Hash = 0, key = 0, sum = 0;
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= k; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    sum += b;
    Hash += a * b;
    Hash %= n;
  }
  key = (n + 1) * n / 2;
  key %= n;
  if (n == 1)
    puts("1");
  else if (sum > n)
    puts("-1");
  else if (sum == n) {
    if (n == 2)
      puts("1");
    else if (Hash != key)
      puts("-1");
    else
      puts("1");
  } else
    puts("1");
  return 0;
}
