#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
int n, m;
map<int, int> cnt;
set<int> ans;
int main() {
  cin >> n >> m;
  while (m--) {
    int k, first;
    cin >> k >> first;
    cnt[k] = first;
  }
  for (int i = 1; i <= 200; ++i) {
    bool flag = false;
    for (int j = 1; j <= 200; ++j)
      if (cnt.find(j) != cnt.end() && cnt[j] != (j - 1) / i + 1) {
        flag = true;
        break;
      }
    if (!flag) ans.insert((n - 1) / i + 1);
  }
  if (ans.size() == 1)
    cout << *ans.begin();
  else
    cout << -1;
  return 0;
}
