#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
using namespace std;
int prime(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
void InitPrime() {
  int pr[100005];
  fill(pr + 1, pr + 1001, 1);
  pr[1] = 0;
  for (int i = 2; i <= 1000; i++)
    if (pr[i])
      for (int j = i + i; j <= 1000; j += i) pr[j] = 0;
}
void AddMOD(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
long long tinh(long long a, long long b, long long c) {
  if (b == 1) return a % c;
  long long x = tinh(a, b / 2, c);
  long long y = (1ll * x * x) % c;
  if (b % 2 != 0) y = (1ll * y * a) % c;
  return y;
}
long long tinh2(long long a, long long n, long long mod = 1000000007) {
  a = a < 0 ? (mod - (-a) % mod) : (a % mod);
  long long r = 1;
  while (n) {
    if (n & 1) r = r * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}
long long n, m;
pair<long long, long long> a[100005];
int main() {
  cin >> n >> m;
  long long l = 1, r = 100;
  for (int i = 1; i <= m; i++) {
    long long k, f;
    cin >> k >> f;
    l = max(l, 1 + (k - 1) / f);
    if (f > 1) r = min(r, (k - 1) / (f - 1));
  }
  l = 1 + (n - 1) / l;
  r = 1 + (n - 1) / r;
  if (l != r)
    cout << -1 << endl;
  else
    cout << l << endl;
  return 0;
}
