#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
int x, y, n;
vector<int> divi[2];
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(x), read(y);
    divi[i & 1].clear();
    if (i == 1) {
      for (int i = 2; i * i <= x; ++i)
        if (x % i == 0) {
          divi[1].push_back(i);
          while (x % i == 0) x /= i;
        }
      if (x > 1) divi[1].push_back(x);
      for (int i = 2; i * i <= y; ++i)
        if (y % i == 0) {
          divi[1].push_back(i);
          while (y % i == 0) y /= i;
        }
      if (y > 1) divi[1].push_back(y);
      sort(divi[1].begin(), divi[1].end());
      divi[1].erase(unique(divi[1].begin(), divi[1].end()), divi[1].end());
    } else {
      for (int j = 0; j < divi[(i & 1) ^ 1].size(); ++j) {
        if (x % divi[(i & 1) ^ 1][j] == 0 || y % divi[(i & 1) ^ 1][j] == 0) {
          divi[i & 1].push_back(divi[(i & 1) ^ 1][j]);
          continue;
        }
      }
    }
  }
  if (divi[n & 1].size())
    printf("%d\n", divi[n & 1][0]);
  else
    puts("-1");
}
