#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int fs[111];
void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  fill(fs, fs + 111, -1);
  for (int i = (0); i < int(m); ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    fs[x] = y;
  }
  set<int> ans;
  for (int k = (1); k < int(111); ++k) {
    bool ok = true;
    for (int i = (0); i < int(111); ++i) {
      if (fs[i] != -1 && fs[i] != i / k) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans.insert((n - 1) / k);
    }
  }
  if (ans.size() != 1) {
    cout << -1;
  } else {
    cout << (*ans.begin()) + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve(cin, cout);
  return 0;
}
