#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[105];
bool ok(int x) {
  int fl = 1;
  for (int i = 1; i <= 100; i++) {
    if (arr[i] and arr[i] != fl) return 0;
    if (i % x == 0) fl++;
  }
  return 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    arr[x] = y;
  }
  if (arr[n]) return printf("%d\n", arr[n]) * 0;
  vector<int> ans;
  for (int i = 1; i <= 101; i++)
    if (ok(i)) ans.push_back((n + i - 1) / i);
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  if (ans.size() > 1)
    puts("-1");
  else
    printf("%d\n", ans[0]);
  return 0;
}
