#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
ostream &operator<<(ostream &os, const vector<int> &v) {
  os << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "}";
  return os;
}
ostream &operator<<(ostream &os, const pair<int, int> &p) {
  return os << " (" << p.first << "," << p.second << ")";
}
int a, b, k, l, m, n, p, q, r, t, x, y, z;
int main() {
  cerr << "go"
       << "\n";
  cin >> a >> m;
  int l = 1;
  int r = INF;
  for (int i = 0; i < m; i++) {
    cin >> n >> x;
    l = max(l, (n + x - 1) / x);
    if (x > 1) r = min(r, (n - 1) / (x - 1));
  }
  cerr << l << ' ' << r << "\n";
  if ((a + l - 1) / l == (a + r - 1) / r) {
    cout << (a + l - 1) / l << "\n";
  } else
    cout << -1 << "\n";
  return 0;
}
