#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2 + 10;
int a[maxn];
int fl[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int k, f;
    cin >> k >> f;
    fl[k] = f;
  }
  int cnt = 0, d = 0;
  vector<int> div;
  for (int i = 1; i <= 100; i++) {
    int f = 1;
    for (int k = 1; k <= 100; k += i) {
      for (int j = 0; j < i; j++) {
        if (fl[k + j] && fl[k + j] != (k + j - 1) / i + 1) {
          f = 0;
          break;
        }
      }
      if (f == 0) break;
    }
    if (f) {
      div.push_back(i);
    }
  }
  set<int> ans;
  for (auto idx : div) ans.insert((n - 1) / idx + 1);
  if (ans.size() == 1)
    cout << *ans.begin() << endl;
  else
    cout << -1 << endl;
  return 0;
}
