#include <bits/stdc++.h>   using namespace std;   struct TnT {     int k, f;   } T[111];   bool cmp(TnT a, TnT b) {     if (a.f == b.f) return a.k < b.k;     return a.f < b.f;   }   map<int, int> t;   int main() {     ios::sync_with_stdio(false);     int n, m, ans = -1;     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> T[i].k >> T[i].f;     sort(T, T + m, cmp);     for (int k = 1; k <= 100; k++) {       int cnt = 1;       for (int i = 1; i <= 110; i += k) {         for (int j = i; j <= i + k - 1; j++) t[j] = cnt;         cnt++;       }       int flag = 1;       for (int i = 0; i < m; i++) {         if (t[T[i].k] != T[i].f) flag = 0;       }       if (flag) {         if (ans == -1)           ans = t[n];         else if (ans != t[n]) {           cout << -1 << endl;           return 0;         }       }     }     cout << ans << endl;     return 0;   }   