#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
int main() {
  int n, m;
  cin >> n >> m;
  --n;
  int l = 1, r = 1000;
  for (int i = 0; i < m; ++i) {
    int k, first;
    cin >> k >> first;
    chkmax(l, (k + first - 1) / first);
    if (first != 1) chkmin(r, (k - 1) / (first - 1));
  }
  int f1 = n / l + 1;
  int f2 = n / r + 1;
  if (f1 != f2)
    cout << "-1\n";
  else
    cout << f1 << '\n';
}
