#include <bits/stdc++.h>
using namespace std;
int n, a[1500000 + 10], b[1500000 + 10], t, cnt[1500000 + 10],
    tag[1500000 + 10];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (register int i = 2; i * i <= max(a[1], b[1]); i++)
    if (a[1] % i == 0 || b[1] % i == 0) {
      while (a[1] % i == 0) a[1] /= i;
      while (b[1] % i == 0) b[1] /= i;
      cnt[++t] = i;
    }
  if (a[1] > 1) cnt[++t] = a[1];
  if (b[1] > 1) cnt[++t] = b[1];
  sort(cnt + 1, cnt + t + 1);
  for (register int i = 2; i <= n; i++)
    for (register int j = t; j >= 1; j--)
      if (a[i] % cnt[j] && b[i] % cnt[j]) tag[j] = 1;
  for (register int i = t; i >= 1; i--)
    if (!tag[i]) {
      cout << cnt[i] << endl;
      return 0;
    }
  cout << -1;
  return 0;
}
