#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool flg = false;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') flg = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flg ? -x : x;
}
int n, k;
int a[200010], b[200010];
long long S;
int main() {
  n = read(), k = read();
  for (int i = 1; i <= k; i++) {
    a[i] = read(), b[i] = read();
    S += b[i];
  }
  if (S > n) return puts("-1"), 0;
  if (S < n) return puts("1"), 0;
  S = 0;
  for (int i = 1; i <= k; i++) S += 1LL * a[i] * b[i];
  puts(S % n != (n - 1LL) * n / 2 % n ? "-1" : "1");
  return 0;
}
