#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  long a[101] = {0};
  for (long i = 1; i <= m; i++) {
    long k, f;
    cin >> k >> f;
    a[k] = f;
  }
  long ans = 0;
  for (long i = 1; i <= 100; i++) {
    long b[101], j;
    for (j = 1; j <= 100; j++) {
      b[j] = j / i + ((j % i) > 0);
      if (a[j] != 0 && b[j] != a[j]) break;
    }
    if (j == 101) {
      if (ans == 0 || ans == b[n])
        ans = b[n];
      else {
        cout << -1;
        return 0;
      }
    }
  }
  cout << ans;
}
