#include <bits/stdc++.h>
using namespace std;
long long n, k, tot;
int main() {
  cin >> n >> k;
  long long startState = 0;
  while (k--) {
    long long pos, val;
    scanf("%lld %lld", &pos, &val);
    tot += val, startState += pos * val, startState %= n;
  }
  if (tot > n) {
    puts("-1");
    return 0;
  }
  if (tot < n) {
    puts("1");
    return 0;
  }
  long long endState = (n * (n + 1) / 2) % n;
  puts(startState == endState ? "1" : "-1");
  return 0;
}
