#include <bits/stdc++.h>
using namespace std;
bool p(int a, int b, int j) {
  int c = a - (j * (b - 1));
  return c > 0 && c <= j;
}
int main() {
  int n, k;
  cin >> k >> n;
  vector<int> v(101, 1);
  for (size_t i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    for (size_t j = 1; j <= 100; j++) {
      if (!p(a, b, j)) v[j] = 0;
    }
  }
  int ans_n = 0, ans = -1;
  for (int i = 1; i <= 100; i++)
    for (int j = 1; j <= 100; j++)
      if (v[j] && p(k, i, j)) {
        if (ans != i) {
          ans_n++;
          ans = i;
        }
      }
  if (ans_n == 1)
    cout << ans;
  else
    cout << -1;
  return 0;
}
