#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& cout, pair<A, B> const& p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream& operator<<(ostream& cout, vector<A> const& v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
void file_io(string taskname) {
  string fin = taskname + ".in";
  string fout = taskname + ".out";
  const char* FIN = fin.c_str();
  const char* FOUT = fout.c_str();
  freopen(FIN, "r", stdin);
  freopen(FOUT, "w", stdout);
  fast_io();
}
int main() {
  fast_io();
  long long n;
  long long k;
  cin >> n >> k;
  long long tot = 0;
  long long sum = 0;
  for (int i = 0; i < (k); i++) {
    long long a, b;
    cin >> a >> b;
    tot += b;
    sum += a * b;
    sum %= n;
  }
  if (tot < n) {
    cout << 1 << endl;
  } else if (tot > n) {
    cout << -1 << endl;
  } else {
    if (n % 2 == 0) {
      if (sum == n / 2) {
        cout << 1 << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      if (sum == 0) {
        cout << 1 << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
}
