#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
int main() {
  int n, k;
  cin >> n >> k;
  int64_t sum_b = 0, sum_ab = 0;
  for (int i = 1; i <= k; ++i) {
    int a = read(), b = read();
    sum_b += b;
    (sum_ab += 1LL * (a - 1) * b) %= n;
  }
  if (sum_b < n || (sum_b == n && (sum_ab - 1LL * (n - 1) * n / 2) % n == 0))
    puts("1");
  else
    puts("-1");
}
