#include <bits/stdc++.h>
using namespace std;
int n, i, m, a, b;
long long as, s;
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d %d", &a, &b);
    s += b;
    as = (as + 1ll * a * b) % n;
  }
  puts(s < n || s == n && as == ((n & 1) ^ 1) * (n / 2) ? "1" : "-1");
}
