#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 150000 + 5;
const int lim = 100000;
long long fgcd(long long a, long long b) {
  if (a == 0ll)
    return b;
  else
    return fgcd(b % a, a);
}
bool isp[max_n];
int n;
int a[max_n], b[max_n];
int main() {
  scanf("%d", &n);
  long long g = 0ll;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    scanf("%d", &b[i]);
    long long q = ((long long)(a[i])) * ((long long)(b[i]));
    g = fgcd(g, q);
  }
  if (g == 1ll) {
    printf("%d\n", -1);
    return 0;
  }
  if (fgcd(g, ((long long)(a[0]))) != 1ll)
    g = fgcd(g, ((long long)(a[0])));
  else
    g = fgcd(g, ((long long)(b[0])));
  for (int d = 2; d < lim + 1; ++d)
    if (g % ((long long)(d)) == 0ll) {
      printf("%d\n", d);
      return 0;
    }
  cout << g << "\n";
  return 0;
}
