#include <bits/stdc++.h>
using namespace std;
int bin1(int k, int f) {
  int l = 0, r = 1000;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if ((k - 1) / m + 1 <= f)
      r = m;
    else
      l = m;
  }
  return r;
}
int bin2(int k, int f) {
  int l = 0, r = 1000;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if ((k - 1) / m + 1 >= f)
      l = m;
    else
      r = m;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  int l = 1, r = 1000;
  for (int i = 0; i < m; i++) {
    int k, f;
    cin >> k >> f;
    int curl = bin1(k, f);
    int curr = bin2(k, f);
    l = max(l, curl);
    r = min(r, curr);
  }
  int ans1 = (n - 1) / l + 1, ans2 = (n - 1) / r + 1;
  if (ans1 != ans2)
    cout << -1;
  else
    cout << ans1;
  return 0;
}
