#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e5 + 1;
const int inf = 1e9 + 7;
const string ABC = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int n, m;
  cin >> n >> m;
  int l = 1;
  int r = n;
  for (int i = 0; i < m; i++) {
    int k, f;
    cin >> k >> f;
    int c = f - 1;
    if (c != 0) {
      int k1 = k - 1;
      while (k1 % (f - 1) != 0) k1--;
      int del = k1 / (f - 1);
      r = min(r, del);
    }
    c = k;
    while (c % f != 0) c++;
    int del = c / f;
    l = max(l, del);
  }
  int e1 = (n + l - 1) / l;
  int e2 = (n + r - 1) / r;
  if (e1 == e2)
    cout << e1;
  else
    cout << -1;
  return 0;
}
