#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int a[N], f[N];
int fl[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  n--;
  fl[0] = 1;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> f[i];
    a[i]--;
    fl[a[i]] = f[i];
  }
  if (fl[n] != 0) {
    cout << fl[n];
    return 0;
  }
  for (int i = n; i < N; ++i) {
    if (fl[i] == 1) {
      cout << 1;
      return 0;
    }
  }
  int a1 = 0, a2 = N;
  for (int i = n; i < N; ++i) {
    if (fl[i] != 0) {
      a2 = fl[i];
      break;
    }
  }
  for (int i = n; i >= 0; --i) {
    if (fl[i] != 0) {
      a1 = fl[i];
      break;
    }
  }
  if (a1 == a2) {
    cout << a1;
    return 0;
  }
  vector<int> t;
  for (int i = 1; i < N; ++i) {
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      if (a[j] / i + 1 != f[j]) {
        ok = false;
        break;
      }
    }
    if (ok) t.push_back(i);
  }
  set<int> ans;
  while (!t.empty()) {
    int MOD = t.back();
    ans.insert(n / MOD + 1);
    t.pop_back();
  }
  if (ans.size() == 1)
    cout << *ans.begin();
  else
    cout << -1;
  return 0;
}
