#include <bits/stdc++.h>
#pragma pick(4);
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  int b, c;
  for (int i = 0; i < m; i++) {
    cin >> b >> c;
    a[i] = {b, c};
  }
  if (m == 0) {
    if (n != 1) {
      cout << -1;
      return 0;
    } else {
      cout << 1 << '\n';
      return 0;
    }
  }
  int now = -1;
  bool f;
  int e;
  for (int i = 1; i <= 101; i++) {
    for (int j = 0; j < m; j++) {
      f = true;
      if (a[j].first % i == 0) {
        if (a[j].second != a[j].first / i) {
          f = false;
        }
      } else {
        if (a[j].second != a[j].first / i + 1) {
          f = false;
        }
      }
      if (!f) {
        break;
      }
      if (j == m - 1) {
        if (now > -1) {
          e = n / i;
          if (n % i != 0) {
            e++;
          }
          if (e != now) {
            cout << -1 << '\n';
            return 0;
          }
        } else {
          now = n / i;
          if (n % i != 0) now++;
        }
      }
    }
  }
  cout << now << ' ';
  return 0;
}
