#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e9;
const long long int MOD = 1e9 + 7;
pair<long long int, long long int> arr[150001];
set<long long int> s;
map<long long int, long long int> mapp;
int main() {
  long long int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;
  long long int a = arr[1].first, b = arr[1].second;
  for (i = 2; i * i <= a; i++) {
    if (a % i != 0) continue;
    while (a % i == 0) a = a / i;
    s.insert(i);
  }
  if (a != 1) s.insert(a);
  for (i = 2; i * i <= b; i++) {
    if (b % i != 0) continue;
    while (b % i == 0) b = b / i;
    s.insert(i);
  }
  if (b != 1) s.insert(b);
  long long int cnt = 1;
  long long int ans = *(s.begin());
  for (auto it : s) {
    cnt = 1;
    for (i = 2; i <= n; i++) {
      if (arr[i].first % it == 0 || arr[i].second % it == 0) cnt++;
    }
    if (cnt == n) {
      ans = it;
      break;
    }
  }
  if (cnt == n)
    cout << ans << "\n";
  else
    cout << "-1\n";
}
