#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
using namespace std;
pair<long long, long long> x[MAXN];
long long k, m;
long long f[MAXN];
long long xxx = 0;
set<long long> s;
bool check(long long a) {
  long long now = 1, kek = 1;
  long long lol = k / a;
  if (k % a) ++lol;
  for (long long i = 1; i <= 100; ++i) {
    f[i] = now;
    ++kek;
    if (kek > a) now++, kek = 1;
  }
  for (long long i = 1; i <= m; ++i) {
    if (f[x[i].first] != x[i].second) return 0;
  }
  if (f[k] != lol) return 0;
  s.insert(lol);
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long i, j, flag = 0, kol, val, res = 0, mda = -1;
  cin >> k >> m;
  if (k == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (i = 1; i <= m; ++i) {
    cin >> x[i].first >> x[i].second;
  }
  for (i = 1; i <= 100; ++i) check(i);
  if (s.size() != 1)
    cout << -1 << endl;
  else {
    kol = *(s.begin());
    cout << kol << endl;
  }
  return 0;
}
