#include <bits/stdc++.h>
using namespace std;
int n, m;
long long tot, fun;
inline int Read() {
  register int r = 0, c = getchar();
  while (c < '0' || '9' < c) c = getchar();
  while ('0' <= c && c <= '9')
    r = (r << 1) + (r << 3) + (c ^ '0'), c = getchar();
  return r;
}
int main() {
  n = Read(), m = Read();
  for (int i = 1; i <= m; i++) {
    int pos = Read(), cnt = Read();
    tot += cnt;
    fun += 1ll * pos * cnt;
  }
  if (tot < n) {
    printf("1\n");
    return 0;
  }
  if (tot > n) {
    printf("-1\n");
    return 0;
  }
  if (fun % n == n * (n + 1ll) / 2 % n)
    printf("1\n");
  else
    printf("-1\n");
  return 0;
}
