#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <typename A,
          typename B = typename enable_if<!is_same<A, string>::value,
                                          typename A::value_type>::type>
ostream& operator<<(ostream& out, A vec) {
  out << '{';
  string sep;
  for (B x : vec) out << sep << x, sep = ", ";
  return out << '}';
}
void dbg_print() { cerr << endl; }
template <typename A, typename... B>
void dbg_print(A a, B... b) {
  cerr << ' ' << a;
  dbg_print(b...);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  ll total = 0, sum = 0;
  while (k--) {
    int a, b;
    cin >> a >> b;
    sum += b;
    total += 1ll * (n - a + 1) * b % n;
  }
  if (sum != n) {
    cout << (sum < n ? 1 : -1) << '\n';
    return 0;
  }
  cout << (total % n == 1ll * n * (n + 1) / 2 % n ? 1 : -1) << '\n';
}
