#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
long long n, a[200010], b[200010], sum, k;
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= k; i++) a[i] = read(), b[i] = read(), sum += b[i];
  if (sum > n) {
    printf("-1\n");
    return 0;
  }
  if (sum < n) {
    printf("1\n");
    return 0;
  }
  sum = 0;
  for (int i = 1; i <= k; i++) sum = (sum + a[i] * b[i] % n) % n;
  if (sum == (n + 1) * n / 2 % n)
    printf("1\n");
  else
    printf("-1\n");
  return 0;
}
