#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], hd;
int c[N], d[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c[i], &d[i]);
  }
  for (int i = 2; i * i <= c[0]; i++) {
    if (c[0] % i == 0) {
      a[hd++] = i;
      while (c[0] % i == 0) c[0] /= i;
    }
  }
  if (c[0] != 1) a[hd++] = c[0];
  for (int i = 2; i * i <= d[0]; i++) {
    if (d[0] % i == 0) {
      a[hd++] = i;
      while (d[0] % i == 0) d[0] /= i;
    }
  }
  if (d[0] != 1) a[hd++] = d[0];
  for (int i = 0; i < hd; i++) {
    int ok = 1;
    for (int j = 1; j < n; j++) {
      if (c[j] % a[i] == 0 || d[j] % a[i] == 0) continue;
      ok = 0;
    }
    if (ok) {
      printf("%d\n", a[i]);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
