#include <bits/stdc++.h>
using namespace std;
struct Union {
  vector<int> p, s;
  Union(int x) {
    p.resize(x + 1, 0);
    s.resize(x + 1, 1);
    for (int j = 1; j <= x; j++) p[j] = j;
  }
  int parent(int u) {
    if (u == p[u]) return u;
    return (p[u] = parent(p[u]));
  }
  bool merge(int u, int v) {
    int p1 = parent(u), p2 = parent(v);
    if (p1 == p2) return 0;
    if (s[p1] > s[p2]) swap(p1, p2);
    s[p2] += s[p1];
    p[p1] = p2;
    return 1;
  }
};
vector<int> primes(long long int x) {
  vector<int> ans;
  for (int j = 2; j * j <= x; j++) {
    if (x % j == 0) {
      ans.push_back(j);
      while (x % j == 0) x /= j;
    }
  }
  if (x != 1) ans.push_back(x);
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  vector<pair<long long int, long long int> > v(n);
  for (int j = 0; j < n; j++) scanf("%lld %lld", &v[j].first, &v[j].second);
  vector<int> ans = primes(v[0].first);
  vector<int> t = primes(v[0].second);
  for (auto i : t) ans.push_back(i);
  for (auto i : ans) {
    bool fg = 0;
    for (int j = 1; j < n; j++) {
      if (v[j].first % i == 0 || v[j].second % i == 0)
        continue;
      else {
        fg = 1;
        break;
      }
    }
    if (fg) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
