#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 3e5;
int ai[N], bi[N], C[N], tot;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &ai[i], &bi[i]);
  for (long long p = 2; p * p <= ai[1]; ++p) {
    if (ai[1] % p == 0) {
      C[++tot] = p;
      while (ai[1] % p == 0) ai[1] /= p;
    }
  }
  if (ai[1] != 1) C[++tot] = ai[1];
  swap(ai[1], bi[1]);
  for (long long p = 2; p * p <= ai[1]; ++p)
    if (ai[1] % p == 0) {
      C[++tot] = p;
      while (ai[1] % p == 0) ai[1] /= p;
    }
  if (ai[1] != 1) C[++tot] = ai[1];
  for (int p = 1; p <= tot; ++p) {
    int fl = 1;
    for (int i = 2; i <= n; ++i)
      if ((ai[i] % C[p]) && (bi[i] % C[p])) {
        fl = 0;
        break;
      }
    if (fl) {
      printf("%d\n", C[p]);
      return 0;
    }
  }
  puts("-1");
}
