#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, lowerlimit = 0, upperlimit = INT_MAX, x, y;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1)
      cout << "1";
    else
      cout << "-1";
    exit(0);
  }
  while (m--) {
    cin >> x >> y;
    lowerlimit = max(lowerlimit, ((x - 1) / y) + 1);
    if (y != 1) upperlimit = min(upperlimit, (x - 1) / (y - 1));
    if (lowerlimit > upperlimit) {
      cout << "-1";
      exit(0);
    }
  }
  if ((n - 1) / lowerlimit != (n - 1) / upperlimit) {
    cout << "-1";
    exit(0);
  }
  cout << (n - 1) / lowerlimit + 1;
}
