#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int maxx = 1, minn = 100;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    maxx = max(maxx, (x - 1) / y + 1);
    if (y > 1) minn = min(minn, (x - 1) / (y - 1));
  }
  maxx = (n - 1) / maxx + 1;
  minn = (n - 1) / minn + 1;
  if (minn == maxx)
    cout << maxx << endl;
  else
    cout << -1 << endl;
  return 0;
}
