#include <bits/stdc++.h>
const bool is_testing = 0;
using namespace std;
const int MAX_VALUE = int(1e9 + 5);
long long get_floor(long long x, long long onone) {
  if (x % onone == 0)
    return x / onone;
  else
    return x / onone + 1;
}
int main() {
  if (is_testing) freopen("/home/birdi/cpp/in.txt", "r", stdin);
  ios::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  long long k, f;
  vector<long long> v(105, -1);
  v[1] = 1;
  vector<pair<long long, long long> > asf(101, {1000, -1});
  asf[1].first = 1;
  while (m--) {
    cin >> k >> f;
    v[k] = f;
    asf[f].first = min(asf[f].first, k);
    asf[f].second = max(asf[f].second, k);
  }
  for (f = 1; f <= n; f++) {
    if (asf[f].first <= n && n <= asf[f].second) {
      cout << f;
      return 0;
    }
  }
  if (v[n] != -1) {
    cout << v[n];
    return 0;
  }
  list<int> res;
  for (int assume = 1; assume < 101; assume++) {
    bool corr = 1;
    for (int t = 1; t < 101 && corr; t++) {
      if (v[t] != -1 && get_floor(t, assume) != v[t]) {
        corr = 0;
      }
    }
    if (corr) res.push_back(assume);
  }
  set<long long> s;
  for (int i : res) s.insert(get_floor(n, i));
  if (s.size() == 1)
    cout << *s.begin();
  else
    cout << -1;
  return 0;
}
