#include <bits/stdc++.h>
using namespace std;
int N, M, x[100001], y[100001], chk[100001];
vector<int> v;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> x[i] >> y[i];
  for (int i = 1; i <= 100; i++) {
    int flat[101] = {0}, ok = 0;
    for (int j = 1; j <= 100; j++) flat[j] = i + flat[j - 1];
    for (int j = 0; j < M; j++) {
      if (flat[y[j]] >= x[j] && flat[y[j] - 1] < x[j]) ok++;
    }
    if (ok == M) {
      for (int j = 1; j <= 100; j++) {
        if (flat[j] >= N && flat[j - 1] < N) {
          if (!chk[j]) {
            chk[j] = 1;
            v.push_back(j);
          }
          break;
        }
      }
    }
  }
  if (v.size() == 1)
    cout << v[0];
  else
    cout << -1;
}
