#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
    a[i].first--;
    a[i].second--;
  }
  int ans = -1;
  for (int tr = 1; tr <= 101; tr++) {
    bool ud = 1;
    for (int i = 0; i < m; i++) {
      if (a[i].first / tr != a[i].second) ud = 0;
    }
    if (ud == 1) {
      if (ans == -1 || ans == (n - 1) / tr + 1)
        ans = (n - 1) / tr + 1;
      else {
        cout << "-1\n";
        return 0;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
