#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, k;
  cin >> n >> k;
  long long sum = 0, inv2 = 0;
  long long vals[2] = {0, 0};
  int mx = 0;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    vals[a & 1] += b;
    inv2 += (a * 1ll * b) % n;
    sum += b;
    mx = max(mx, b);
  }
  if (sum > n) {
    cout << "-1\n";
    return 0;
  }
  if (n <= 2 || mx < 2) {
    cout << "1\n";
    return 0;
  }
  if (sum < n) {
    cout << "1\n";
    return 0;
  }
  inv2 %= n;
  inv2 -= (n * 1ll * (n + 1) / 2) % n;
  inv2 %= n;
  if (inv2 != 0) {
    cout << "-1\n";
    return 0;
  }
  if (n % 2 == 0 && vals[1] % 2 != vals[0] % 2) {
    cout << "-1\n";
    return 0;
  }
  cout << "1\n";
}
