#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int INF = 4127;
const int mod = 475;
int a[1005], b[1005];
set<int> rofl;
int main() {
  int n, m, ans = 0, sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= 2000; i++) {
    int x = i;
    bool ok = 1;
    for (int j = 1; j <= m; j++) {
      if ((a[j] + x - 1) / x != b[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      rofl.insert((n + x - 1) / x);
    }
  }
  if (rofl.size() != 1) {
    cout << -1;
    return 0;
  }
  cout << *rofl.begin();
}
