#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
pair<long long, long long> f[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long tot = 0;
  for (int i = (1); i < (m + 1); ++i) {
    cin >> f[i].first >> f[i].second;
    tot += f[i].second;
  }
  if (tot > n) {
    cout << "-1";
    return 0;
  }
  if (tot < n) {
    cout << "1";
    return 0;
  }
  long long p = 0;
  for (int i = (1); i < (m + 1); ++i) {
    p += f[i].first * f[i].second;
  }
  if (n % 2 == 0) {
    cout << (p % n != 0 && p * 2 % n == 0 ? "1" : "-1");
  } else {
    cout << (p % n ? "-1" : "1");
  }
  return 0;
}
