#include <bits/stdc++.h>
using namespace std;
int fnd, m;
int minlevel, maxlevel;
int k, curlevel;
int curans = 0;
unordered_map<int, int> known;
vector<pair<int, int>> fl;
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d %d", &fnd, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &k, &curlevel);
    fl.push_back({k, curlevel});
    if (curlevel > k) {
      printf("-1\n");
      return 0;
    }
    known[k] = curlevel;
  }
  curans = -1;
  if (known.find(fnd) != known.end()) {
    printf("%d\n", known[fnd]);
    return 0;
  }
  for (int num = 1; num <= 100; num++) {
    bool isgood = true;
    for (auto el : fl) {
      int toch = el.first / num;
      if (el.first % num != 0) toch++;
      if (el.second != toch) {
        isgood = false;
        break;
      }
    }
    if (!isgood) continue;
    int toch = fnd / num;
    if (fnd % num != 0) toch++;
    if (curans == -1 || curans == toch)
      curans = toch;
    else {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", curans);
  return 0;
}
