#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const long long MAXN = 1000001;
const long long MAXVAL = 5000000;
const long long INF = (long long)1e17 + 100;
const long long MOD = (long long)1e9 + 7;
string failMessage;
void fail() {
  cout << failMessage;
  exit(0);
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > q(m);
  for (int i = 0; i < m; i++) {
    cin >> q[i].first >> q[i].second;
  }
  set<int> ans;
  for (int i = 1; i <= 10000; i++) {
    bool good = true;
    for (int j = 0; j < m && good; j++) {
      if (!(q[j].second == (q[j].first - 1) / i + 1)) {
        good = false;
      }
    }
    if (good) {
      ans.insert((n - 1) / i + 1);
    }
  }
  if (ans.size() == 1) {
    cout << *ans.begin();
  } else {
    cout << -1;
  }
}
int main() {
  const string FILENAME = "input";
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  solve();
}
