#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long x, y, s1, s2;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * f;
}
signed main() {
  n = read(), k = read();
  while (k--) x = read(), y = read(), s1 += x * y, s2 += y;
  if (s2 < n) {
    puts("1");
    return 0;
  } else if (s2 > n) {
    puts("-1");
    return 0;
  } else if (s1 % n == n * (n + 1) / 2 % n)
    puts("1");
  else
    puts("-1");
  return 0;
}
