#include <bits/stdc++.h>
using namespace std;
const int Z = (int)3e3 + 228;
const int N = (int)2e5 + 228;
const int INF = (int)1e9 + 228;
const long long LLINF = (long long)1e18 + 228;
const int MOD = 1000 * 1000 * 1000 + 7;
int k[111], f[111], h[111];
bool can(int x, int n, int m) {
  int cur = 1;
  for (int i = 1; i <= 100; i++) {
    h[i] = cur;
    if (i % x == 0) cur++;
  }
  for (int i = 1; i <= m; i++)
    if (h[k[i]] != f[i]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v;
  for (int i = 1; i <= m; i++) cin >> k[i] >> f[i];
  if (!m) {
    if (n == 1)
      cout << 1;
    else
      cout << -1;
    return 0;
  }
  set<int> mn;
  for (int i = 1; i <= 100; i++)
    if (can(i, n, m)) mn.insert(h[n]);
  if (mn.size() != 1)
    cout << -1;
  else
    cout << *mn.begin();
  return 0;
}
