#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long solve() {
  long long n, k;
  cin >> n >> k;
  long long e = 0, s = 0;
  long long o = 0;
  for (long long i = 1; i < k + 1; i++) {
    long long a, b;
    cin >> a >> b;
    s += b;
    e += b * a;
    e %= n;
  }
  if (s < n) {
    cout << 1 << "\n";
    return 0;
  }
  if (s > n) {
    cout << -1 << "\n";
    return 0;
  }
  if ((n * (n + 1) / 2) % n == e % n) {
    cout << 1 << "\n";
    return 0;
  }
  cout << -1 << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
