#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
const double PI = acos(-1);
const int X[] = {1, -1, 0, 0};
const int Y[] = {0, 0, 1, -1};
const int mod = 1e9 + 7;
int n, m, k[105], f[105], ans, cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> k[i] >> f[i];
  }
  for (int i = 1; i <= 100; i++) {
    bool g = 1;
    for (int j = 1; j <= m; j++) {
      if (k[j] / i + (k[j] % i != 0) != f[j]) {
        g = 0;
      }
    }
    if (g) {
      ans = i;
    }
  }
  for (int i = 1; i <= 100; i++) {
    bool g = 1;
    for (int j = 1; j <= m; j++) {
      if (k[j] / i + (k[j] % i != 0) != f[j]) {
        g = 0;
      }
    }
    if (g) {
      if (n / i + (n % i != 0) != n / ans + (n % ans != 0)) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << n / ans + (n % ans != 0);
  return 0;
}
