#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, l = 0, r = 999999999999, m;
  cin >> n >> m;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  if (m == 0) {
    cout << -1;
    return 0;
  }
  for (long long i = 0; i < m; i++) {
    long long c, v, l_for_c, r_for_c;
    cin >> c >> v;
    if (v == 1) {
      l = max(l, c);
      continue;
    }
    if (c % v == 0) {
      l_for_c = c / v;
    } else {
      l_for_c = c / v + 1;
    }
    if (c % (v - 1) == 0)
      r_for_c = c / (v - 1) - 1;
    else
      r_for_c = c / (v - 1);
    l = max(l, l_for_c);
    r = min(r, r_for_c);
  }
  set<short> ans;
  ans.insert((n % l == 0 ? n / l : n / l + 1));
  ans.insert((n % r == 0 ? n / r : n / r + 1));
  if (ans.size() > 1)
    cout << -1;
  else {
    auto it = ans.begin();
    cout << *it;
  }
}
