#include <bits/stdc++.h>
int n, m;
int *k = nullptr, *f = nullptr;
bool has(int flats) {
  for (int i = 0; i < m; i++) {
    if (k[i] / flats + (bool)(k[i] % flats) != f[i]) return false;
  }
  return true;
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cin >> n >> m;
  k = new int[m];
  f = new int[m];
  for (int i = 0; i < m; i++) {
    std::cin >> k[i] >> f[i];
  }
  int val = 0, out = -1;
  for (int flats = 1; flats <= 100; flats++) {
    if (has(flats)) {
      if (n / out + (bool)(n % out) != n / flats + (bool)(n % flats)) val++;
      out = flats;
    }
    if (val > 1) break;
  }
  if (val > 1 || val == 0)
    std::cout << -1;
  else
    std::cout << n / out + (bool)(n % out);
  delete[] k;
  delete[] f;
  return 0;
}
