#include <bits/stdc++.h>
using namespace std;
int rd() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * f;
}
int n, k, flag;
long long sum, sum1, sum2;
int main() {
  n = rd();
  k = rd();
  sum2 = 1LL * n * (n - 1) / 2 % n;
  for (int i = 1, a, b; i <= k; i++) {
    a = rd();
    b = rd();
    sum += b;
    sum1 = (sum1 + 1LL * a * b % n) % n;
  }
  if (sum > n)
    puts("-1");
  else if (sum < n)
    puts("1");
  else if (sum1 == sum2)
    puts("1");
  else
    puts("-1");
  return 0;
}
