#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  long long sum1 = 0;
  long long sum2 = 0;
  long long sum3 = (long long)n * (n - 1) / 2;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a %= n;
    sum1 += b;
    sum2 += (long long)a * b;
  }
  int ans = 0;
  if (sum1 < n)
    ans = 1;
  else if (sum1 > n)
    ans = -1;
  else if (sum2 % n == sum3 % n)
    ans = 1;
  else
    ans = -1;
  cout << ans << endl;
  return 0;
}
