#include <bits/stdc++.h>
using namespace std;
struct kv {
  int kv, et;
};
kv a[101];
bool cmp(kv n1, kv n2) {
  if (n1.et != n2.et) return n1.et < n2.et;
  if (n1.kv != n2.kv) return n1.kv < n2.et;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> a[i].kv >> a[i].et;
  sort(a + 1, a + m + 1, cmp);
  if (m == 0) {
    if (n == 1)
      cout << 1;
    else
      cout << -1;
    return 0;
  }
  int anstemp = -1;
  bool y = false;
  for (int ans = 1; ans <= 101; ans++) {
    bool x = true;
    int cntkvl = 1, cntkvr = ans, cntet = 1;
    for (int i = 1; i <= m; i++) {
      if (a[i].et > cntet) {
        cntkvl = (a[i].et - 1) * ans + 1;
        cntkvr = a[i].et * ans;
        cntet = a[i].et;
      }
      if (a[i].kv >= cntkvl && a[i].kv <= cntkvr) {
        continue;
      } else {
        x = false;
        break;
      }
    }
    if (x) {
      if (y) {
        if (anstemp != n / ans + (n % ans != 0)) {
          cout << -1;
          return 0;
        }
      }
      anstemp = n / ans + (n % ans != 0);
      y = true;
    }
  }
  cout << anstemp;
  return 0;
}
