#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = 105;
using namespace std;
int n, m, k[N], f[N], cnt[N], mx[N], mn[N];
set<int> st;
int main() {
  cin >> n >> m;
  mn[1] = 1;
  mx[1] = 1;
  for (int i = 1; i <= m; i++) {
    cin >> k[i] >> f[i];
  }
  for (int i = 1; i <= 300; i++) {
    bool good = true;
    for (int j = 1; j <= m; j++) {
      if ((k[j] - 1) / i + 1 != f[j]) good = false;
    }
    if (good) st.insert((n - 1) / i + 1);
  }
  if ((int)st.size() == 1)
    cout << *(st.begin()) << endl;
  else
    cout << -1 << endl;
  return 0;
}
