#include <bits/stdc++.h>
const int inf = 0x7fffffff;
using namespace std;
int a[105];
int main() {
  int n, m;
  int each;
  int flag, b;
  cin >> n >> m;
  flag = 0;
  for (int i = 0; i < m; i++) {
    int k, f;
    scanf("%d%d", &k, &f);
    if (k == n) {
      flag = 1;
      b = f;
    } else if (k > n && f == 1) {
      flag = 1;
      b = 1;
    }
    a[k] = f;
  }
  if (flag) {
    printf("%d\n", b);
    return 0;
  } else if (n == 1) {
    printf("1\n");
    return 0;
  }
  int maybe = 0, ans;
  for (each = 1; each <= 100; each++) {
    int ok = 1;
    for (int i = 1, ff = 1; i <= 100; i += each, ff++) {
      for (int j = i; j <= 100 && j < i + each; j++) {
        if (a[j] && a[j] != ff) {
          ok = 0;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok) {
      if (maybe == 1) {
        if (ans != (n + (each - 1)) / each) {
          maybe = 2;
          break;
        }
      } else {
        maybe = 1;
        ans = (n + (each - 1)) / each;
      }
    }
  }
  if (maybe == 1)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
