#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, a, b;
  long long sum = 0, kali = 0;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a >> b;
    sum += b;
    kali += (1LL * a * b) % n;
  }
  if (sum > n)
    cout << -1 << '\n';
  else if (sum < n)
    cout << 1 << '\n';
  else if (n % 2 == 0 && kali % n == n / 2)
    cout << 1 << '\n';
  else if (n % 2 == 1 && kali % n == 0)
    cout << 1 << '\n';
  else
    cout << -1 << '\n';
  return 0;
}
