#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, m = 0, l = 1, r = 1000, k = 0, f = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &k, &f);
    l = max(l, 1 + (k - 1) / f);
    if (f > 1) {
      r = min(r, (k - 1) / (f - 1));
    }
  }
  l = 1 + (n - 1) / l;
  r = 1 + (n - 1) / r;
  if (l == r) {
    printf("%d", l);
  } else {
    printf("-1");
  }
  return 0;
}
