#include <bits/stdc++.h>
using namespace std;
const int MX = 105;
int main() {
  int n, m, x, y;
  while (cin >> n >> m) {
    vector<int> floors(MX);
    for (int i = 0; i < m; ++i) {
      cin >> x >> y;
      floors[x] = y;
    }
    set<int> answer;
    for (int i = 1; i < MX; ++i) {
      int cur = 1;
      vector<int> tmpf = floors;
      bool ok = true;
      for (int j = 1; j < MX && ok;) {
        int k = 0;
        while (k < i && j < MX) {
          if (tmpf[j] && tmpf[j] != cur) {
            ok = false;
            break;
          }
          tmpf[j] = cur;
          j++;
          k++;
        }
        cur++;
      }
      if (ok) {
        answer.insert(tmpf[n]);
      }
    }
    cout << (answer.size() != 1 ? -1 : *answer.begin()) << endl;
  }
  return 0;
}
