#include <bits/stdc++.h>
using namespace std;
int n, m, ans = -1;
int k[105], f[105];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> k[i] >> f[i];
  for (int i = 1; i < 105; i++) {
    int chk = 1;
    for (int j = 0; j < m; j++)
      if ((k[j] + i - 1) / i != f[j]) chk = 0;
    if (!chk) continue;
    int tans = (n + i - 1) / i;
    if (ans == -1) ans = tans;
    if (ans != -1 and ans != tans) {
      puts("-1");
      return 0;
    }
  }
  cout << ans << '\n';
  return 0;
}
