#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void showpq(vector<long long> gq) {
  vector<long long> g = gq;
  reverse(g.begin(), g.end());
  while (!g.empty()) {
    cout << g.back() << " ";
    g.pop_back();
  }
  cout << '\n';
}
bool lundu(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    long long n, m, a, b, mx = 0;
    cin >> n >> m;
    vector<pair<long long, long long>> koko;
    for (long long i = 0; i < m; i++) {
      cin >> a >> b;
      mx = (mx < a ? a : mx);
      koko.push_back({a, b});
    }
    mx = (mx < n ? n : mx);
    sort(koko.begin(), koko.end(), lundu);
    vector<long long> av;
    for (long long i = 1; i <= mx; ++i) {
      bool chk = true;
      for (long long j = 0; j < koko.size(); ++j) {
        long long tm = (long long)(koko[j].first / i);
        if (koko[j].first % i) tm++;
        if (koko[j].second != tm) {
          chk = false;
          break;
        }
      }
      if (chk) {
        av.push_back(i);
      }
    }
    set<long long> bhk;
    for (long long i = 0; i < av.size(); i++) {
      long long tm = (long long)(n / av[i]);
      if (n % av[i]) tm++;
      bhk.insert(tm);
    }
    if (bhk.size() != 1) {
      cout << -1;
    } else {
      long long tm = *bhk.begin();
      cout << tm;
    }
  }
  return 0;
}
