#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n, m, ans = 0;
pair<int, int> a[200010];
inline bool jud(int x) {
  for (int i = 1; i <= m; ++i)
    if ((a[i].first - 1) / x + 1 != a[i].second) return 0;
  return 1;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    a[i].first = read();
    a[i].second = read();
  }
  for (int x = 1; x <= 100; ++x)
    if (jud(x)) {
      if (ans && ans != (n - 1) / x + 1) {
        puts("-1");
        return 0;
      } else
        ans = (n - 1) / x + 1;
    }
  printf("%d\n", ans);
  return 0;
}
