#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)998244353;
const int SIZE = 100;
const long long INF = 1LL << 60;
const double eps = 1e-4;
const double PI = 3.1415926535897932;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long s = 0;
  long long ms = 0;
  for (int i = 0; i < (k); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    s += b;
    ms = (ms + (long long)a * b) % n;
  }
  if (s > n) puts("-1");
  if (s < n) puts("1");
  if (s == n) {
    long long leg = ((long long)n * (n - 1) / 2) % n;
    if (ms == leg)
      puts("1");
    else
      puts("-1");
  }
}
