#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000], c[100000];
int main() {
  int n, m;
  cin >> n >> m;
  int u = 0;
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) b[i]--;
  for (int i = 1; i <= 200; i++) {
    bool cd = true;
    for (int j = 0; j < m; j++)
      if ((a[j] < b[j] * i + 1) || (a[j] > b[j] * i + i)) cd = false;
    if (cd == true) {
      c[((n - 1) / i) + 1]++;
      u = i;
    }
  }
  int kol = 0;
  int h = 0;
  for (int i = 1; i <= 200; i++)
    if (c[i] > 0) {
      kol++;
      h = i;
    }
  if (kol == 1)
    cout << h;
  else
    cout << -1;
}
