#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9;
const long long int N = 200005;
struct xx {
  long long int flat, floor;
} a[N];
void solve() {
  long long int i, j, k, n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << 1;
    return;
  } else if (m == 0) {
    cout << -1;
    return;
  }
  for (long long int i = 0; i < m; i++) cin >> a[i].flat >> a[i].floor;
  long long int c = -1;
  for (long long int i = 0; i < m; i++)
    c = max((a[i].flat + a[i].floor - 1) / a[i].floor, c);
  set<long long int> st;
  while (c <= 100) {
    long long int l, r;
    j = 1;
    for (long long int i = 0; i < m; i++) {
      r = a[i].floor * c;
      l = r - c + 1;
      if (a[i].flat > r || a[i].flat < l) {
        j = 0;
        break;
      }
    }
    if (j == 0) break;
    if (j == 1) st.insert(c);
    c++;
  }
  long long int prev = -1;
  for (auto it : st) {
    j = (it + n - 1) / it;
    if (prev == -1)
      prev = j;
    else if (prev != j) {
      cout << -1;
      return;
    }
  }
  cout << prev;
}
int main() {
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
