#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, a[150005], b[150005], x = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    x = gcd(a[i] * b[i], x);
  }
  if (x == 1) return puts("-1\n"), 0;
  for (int i = 1; i <= n; i++) {
    gcd(x, a[i]) > 1 ? x = gcd(x, a[i]) : x = gcd(x, b[i]);
  }
  return cout << x << "\n", 0;
}
