#include <bits/stdc++.h>
using namespace std;
int long long n, m, c[55], ans = 1e18 + 7, k = 0, d[10], l, r, j, y;
pair<int long long, int long long> p[105];
set<int long long> q;
bool check(int x) {
  for (int i = 1; i <= m; i++) {
    if ((p[i].first + x - 1) / x != p[i].second) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  if (n == 1 && m == 0) {
    cout << 1;
    return 0;
  }
  for (j = 1; j <= 100005; j++) {
    if (check(j)) {
      k++;
      q.insert((j + n - 1) / j);
    }
  }
  if (q.size() == 1) {
    int long long ans = *q.begin();
    cout << ans << endl;
  } else
    cout << "-1";
}
