#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k, f, f1, f2, cond, ans, i, j;
  cin >> n >> m;
  n--;
  vector<int> V(100);
  for (i = 0; i < 100; i++) {
    V[i] = -1;
  };
  for (i = 0; i < m; i++) {
    cin >> k >> f;
    k--;
    f--;
    V[k] = f;
  }
  f1 = -1;
  f2 = 101;
  for (i = n; i >= 0; i--) {
    if (V[i] != -1) {
      f1 = V[i];
      break;
    }
  }
  for (i = n; i < 100; i++) {
    if (V[i] != -1) {
      f2 = V[i];
      break;
    }
  }
  ans = -1;
  cond = 1;
  for (i = 1; i <= 100; i++) {
    for (j = 0; j < 100; j++) {
      if (V[j] != -1 && V[j] != j / i) break;
    }
    if (j == 100) {
      if (f1 <= n / i && n / i <= f2 && (V[n] == -1 || n / i == V[n])) {
        if (cond == 1 && ans == -1)
          ans = n / i;
        else {
          if (ans != n / i) cond = 0;
        }
      }
    }
  }
  if (cond == 0)
    ans = -1;
  else
    ans++;
  cout << ans << '\n';
}
