#include <bits/stdc++.h>
using namespace std;
int cmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  long long int n, i, a, b;
  long long int prod;
  long long int ans = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> a >> b;
    prod = a * b;
    if (!i)
      ans = a * b;
    else
      ans = gcd(ans, prod);
  }
  if (ans == 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (ans % a == 0)
    ans = a;
  else if (ans % b == 0)
    ans = b;
  long long int res = 0;
  if (ans % 2 == 0) {
    res = 2;
    cout << "2" << endl;
    return 0;
  }
  int val = 0;
  for (i = 3; i <= sqrt(ans); i += 2) {
    if (ans % i == 0) {
      res = i;
      cout << res << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
