#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  long long n;
  cin >> n;
  vector<long long> v, a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    long long t = a[i] / gcd(a[i], b[i]) * b[i];
    v.push_back(t);
  }
  for (int i = 1; i < n; i++) {
    v[i] = gcd(v[i - 1], v[i]);
  }
  if (v[n - 1] == 1) {
    cout << -1 << endl;
    return 0;
  }
  long long ans = v[n - 1];
  for (int i = 0; i < n; i++) {
    if (gcd(ans, a[i]) != 1) {
      ans = gcd(ans, a[i]);
    } else {
      ans = gcd(ans, b[i]);
    }
  }
  cout << ans << endl;
}
