#include <bits/stdc++.h>
using namespace std;
int o[3], f[3], p[3], ans[1005][1005], a[1005][1005][3];
void solve() {
  int n, k;
  long long s = 0, c = 0;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int a, b;
    cin >> a >> b;
    s = (s + 1ll * a * b) % n;
    c += b;
  }
  if (c > n) return (void)(cout << -1);
  if (c < n) return (void)(cout << 1);
  if (s == (1ll * n * (n + 1) / 2) % n)
    cout << 1;
  else
    cout << -1;
}
signed main() {
  ios::sync_with_stdio(false);
  int T;
  T = 1;
  while (T--) solve();
  return 0;
}
