#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int N = 101;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int a[N], maxf, ans;
int d[N];
bool mul;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k, f;
    cin >> k >> f;
    a[k] = f;
    maxf = max(maxf, f);
  }
  int now = 1;
  for (; now <= 100; now++) {
    int line = 1;
    bool ok = 1;
    for (int i = 1; i <= 100; i++) {
      if (a[i] && a[i] != line) {
        ok = 0;
        break;
      }
      if (i == n && ans && d[n] != line) {
        mul = 1;
      }
      if (i % now == 0) {
        line++;
      }
    }
    if (mul && ok) {
      ans = -1;
      break;
    }
    if (ok) {
      line = 1;
      for (int i = 1; i <= 100; i++) {
        d[i] = line;
        if (i % now == 0) {
          line++;
        }
      }
      ans = d[n];
    }
  }
  cout << ans << endl;
  return 0;
}
