#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int i = 0;
  int l[k], r[k];
  unsigned long s[200001] = {0};
  int idx = 0;
  int tmp;
  while (i < k) {
    scanf("%d%d", &l[i], &r[i]);
    tmp = l[i];
    while (tmp <= r[i]) {
      s[idx] = tmp;
      tmp++;
      idx++;
    }
    i++;
  }
  unsigned long sum = 1;
  i = 0;
  int j;
  int ans;
  int cnt;
  while (s[i] != 0) {
    j = i;
    ans = -1;
    while ((ans = n % s[j]) && s[j] != 0) {
      j++;
    }
    if (ans == 0) {
    }
    i++;
  }
}
