#include <bits/stdc++.h>
using namespace std;
const int max_size = 2e5;
int num, n;
int arr[max_size];
int brr[max_size];
int prime[max_size];
void get_prime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime[num++] = i;
      while (x % i == 0) x = x / i;
    }
  }
  if (x > 1) prime[num++] = x;
}
int main() {
  while (cin >> n) {
    num = 0;
    int ans = -1;
    for (int i = 0; i < n; i++) cin >> arr[i] >> brr[i];
    get_prime(arr[0]);
    get_prime(brr[0]);
    for (int i = 0; i < num; i++) {
      bool vis = true;
      for (int j = 0; j < n; j++) {
        if (arr[j] % prime[i] != 0 && brr[j] % prime[i] != 0) {
          vis = false;
          break;
        }
      }
      if (vis) {
        ans = prime[i];
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
