#include <bits/stdc++.h>
void Solve();
int main() { Solve(); }
using namespace std;
const long long INF = 1e9 + 1;
vector<long long> zFunction(string s) {
  vector<long long> z(s.size(), 0);
  long long l = 0, r = 0;
  z[0] = -1;
  for (long long i = (1); i < (s.size()); i++) {
    if (l <= i && i < r) {
      z[i] = min(z[i - l], r - i);
    }
    while (true) {
      if (z[i] + i < s.size() && s[z[i] + i] == s[z[i]])
        z[i]++;
      else
        break;
    }
    long long currentL = i;
    long long currentR = i + z[i];
    if (currentR > r) {
      r = currentR;
      l = currentL;
    }
  }
  return z;
}
void Solve() {
  long long n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << 1;
    return;
  }
  vector<pair<long long, long long> > a(m);
  for (long long i = (0); i < (m); i++) {
    cin >> a[i].first >> a[i].second;
  }
  long long answ = -1;
  for (long long cf = (1); cf < (101); cf++) {
    for (long long i = (0); i < (m); i++) {
      long long k = a[i].first / cf;
      if (a[i].first % cf != 0) k++;
      if (k != a[i].second) break;
      if (i + 1 == m) {
        k = n / cf;
        if (n % cf != 0) k++;
        if (answ != -1 && answ != k) {
          cout << -1;
          return;
        }
        answ = k;
      }
    }
  }
  cout << answ;
}
