#include <bits/stdc++.h>
using namespace std;
long long bin(int a, int n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    int cur = bin(a, n / 2);
    return (cur * cur);
  } else {
    int cur = bin(a, n - 1);
    return (cur * a);
  }
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
  }
  vector<long long> q;
  for (int fl = 1; fl < 10000; fl++) {
    bool flag = 1;
    for (int i = 0; i < m; i++) {
      if (((a[i].first + fl - 1) / fl) == a[i].second)
        continue;
      else {
        flag = 0;
        break;
      }
    }
    if (flag) {
      q.push_back(fl);
    }
  }
  set<long long> ans;
  for (auto i : q) {
    ans.insert((n + i - 1) / i);
  }
  if (ans.size() != 1) {
    cout << -1;
  } else
    cout << *ans.begin();
  return 0;
}
