#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> flat(m), flr(m);
  unordered_set<int> mp;
  for (int i = 0; i < m; i++) cin >> flat[i] >> flr[i];
  for (int j = 1; j <= 100; j++) {
    bool flag = true;
    for (int i = 0; i < m && flag; i++) {
      if ((flat[i] - 1) / j != flr[i] - 1) flag = false;
    }
    if (flag) mp.insert((n - 1) / j + 1);
  }
  if (mp.size() == 1)
    cout << *(mp.begin()) << endl;
  else
    cout << -1 << endl;
}
