#include <bits/stdc++.h>
using namespace std;
int nm[101][101];
int main() {
  int n, m;
  set<int> ans;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k, f;
    cin >> k >> f;
    nm[f][k] = 1;
  }
  for (int p = 1; p <= 100; p++) {
    int k = 1;
    int cui = -1;
    int ac = 0;
    for (int i = 1; i <= 100; i++) {
      for (int l = 1; l <= p; l++) {
        if (k > 100) break;
        if (nm[i][k] == 1) ac++;
        if (k == n) cui = i;
        k++;
      }
    }
    if (ac == m) ans.insert(cui);
  }
  cout << (ans.size() == 1 ? *ans.begin() : -1);
}
