#include <bits/stdc++.h>
using namespace std;
int a[105], b[105];
set<int> s;
int main() {
  int n, m, i, j, cnt = 0, ans, temp;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
  }
  for (i = 1; i <= 100; i++) {
    for (j = 1; j <= m; j++) {
      temp = a[j] / i;
      if (a[j] % i != 0) temp++;
      if (temp != b[j]) break;
    }
    if (j == m + 1) {
      temp = n / i;
      if (n % i != 0) temp++;
      s.insert(temp);
    }
  }
  if (s.size() == 1)
    cout << *(s.begin()) << "\n";
  else
    cout << "-1\n";
  return 0;
}
