#include <bits/stdc++.h>
const int N = 500;
std::pair<long long, long long> shit[N];
int main(void) {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%lld%lld", &shit[i].first, &shit[i].second);
  }
  long long res = -1, sh = 0;
  for (int k = 1; k <= 100; ++k) {
    long long flag = 1;
    for (int i = 0; i < m; ++i) {
      if ((shit[i].first - 1) / k != shit[i].second - 1) {
        flag = 0;
      }
    }
    if (flag == 1) {
      ++flag;
      long long answer = (n - 1) / k + 1;
      ;
      sh += (answer != res);
      res = answer;
    }
  }
  if (sh == 1) {
    printf("%lld\n", res);
  } else {
    printf("-1\n");
  }
  return 0;
}
