#include <bits/stdc++.h>
using namespace std;
void doRoutine() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  doRoutine();
  int64_t id, m;
  cin >> id >> m;
  --id;
  vector<int64_t> k(m), f(m);
  for (int64_t i = 0; i < m; ++i) {
    cin >> k[i] >> f[i];
    --k[i];
    --f[i];
  }
  set<int64_t> res;
  for (int64_t e = 1; e < 200; ++e) {
    bool is_good = true;
    for (int64_t i = 0; i < m; ++i) {
      if (!(k[i] >= e * f[i] && k[i] < e * (f[i] + 1))) {
        is_good = false;
      }
    }
    if (is_good) {
      for (int64_t cur = 0; cur < 200; ++cur) {
        if (id >= e * cur && id < e * (cur + 1)) {
          res.insert(cur);
        }
      }
    }
  }
  if (res.size() > 1) {
    cout << -1 << endl;
  } else {
    cout << *res.begin() + 1;
  }
  return 0;
}
