#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int MAXN = 1e3 + 10;
const int MAXM = 2e5 + 10;
int k[110], f[110];
vector<int> vec;
int main() {
  vec.clear();
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &k[i], &f[i]);
  set<int> se;
  int ans = -1;
  for (int i = 1; i <= 100; i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int l = (f[j] - 1) * i + 1;
      int r = f[j] * i;
      if (k[j] < l || k[j] > r) {
        flag = false;
        break;
      }
    }
    if (flag) {
      se.insert((n - 1) / i + 1);
      ans = (n - 1) / i + 1;
    }
  }
  if (se.size() != 1) ans = -1;
  printf("%d\n", ans);
  return 0;
}
