#include <bits/stdc++.h>
using namespace std;
int mx(int a, int b) { return a > b ? a : b; }
int mn(int a, int b) { return a < b ? a : b; }
int main(void) {
  vector<int> a(101, -1);
  int n, m;
  cin >> n >> m;
  int min = 1, max = 10e10;
  int miNFloor = 1;
  int maxFloor = 10e10;
  for (int i = 0; i < m; i++) {
    int atazh, kvartira;
    cin >> kvartira;
    cin >> atazh;
    if (atazh != 1) {
      max = mn(max, floor((double)(kvartira - 1) / (atazh - 1)));
    }
    min = mx(min, ceil(((double)kvartira) / atazh));
    if (n > kvartira) {
      miNFloor = mx(miNFloor, atazh);
    } else if (n < kvartira) {
      maxFloor = mn(maxFloor, atazh);
    } else {
      miNFloor = maxFloor = atazh;
    }
  }
  miNFloor = mx(miNFloor, ceil(((double)n) / min));
  maxFloor = mn(maxFloor, ceil(((double)n) / max));
  miNFloor == maxFloor ? cout << miNFloor : cout << -1 << "\n";
  return 0;
}
