#include <bits/stdc++.h>
using namespace std;
const int N = 150;
int n, m, x, f, t, s = 0, ans = 0;
int mn[N] = {};
int mx[N] = {};
int main() {
  cin >> n >> m;
  fill_n(mn, N, N);
  mn[1] = 1;
  mx[1] = 1;
  for (int i = 0; i < m; i++) {
    cin >> x >> f;
    if (x == n) ans = f;
    mn[f] = min(mn[f], x);
    mx[f] = max(mx[f], x);
  }
  for (int i = 1; i < N; i++) {
    bool f = true;
    for (int j = 1; j < N; j++) {
      if (mx[j] && !(mn[j] >= i * (j - 1) + 1 && mx[j] <= i * j)) f = false;
    }
    if (f) {
      int d = n / i + (n % i != 0);
      if (s && d != s)
        s = -1;
      else if (s != -1)
        s = d;
    }
  }
  if (ans)
    cout << ans;
  else
    cout << (s > 0 ? s : -1);
  return 0;
}
