#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, n, i, j, k, h = 0;
  cin >> n;
  long long int a[n], b[n];
  for (i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  if (n == 1) cout << a[0] << endl;
  if (n > 1) {
    set<long long int> s1, s, s3;
    set<long long int>::iterator jt, it;
    j = a[0];
    while (j % 2 == 0) {
      s.insert(2);
      j /= 2;
    }
    for (k = 3; k <= sqrt(j); k = k + 2) {
      while (j % k == 0) {
        s.insert(k);
        j /= k;
      }
    }
    if (j > 2) s.insert(j);
    j = b[0];
    while (j % 2 == 0) {
      s.insert(2);
      j /= 2;
    }
    for (k = 3; k <= sqrt(j); k = k + 2) {
      while (j % k == 0) {
        s.insert(k);
        j /= k;
      }
    }
    if (j > 2) s.insert(j);
    j = a[1];
    while (j % 2 == 0) {
      s1.insert(2);
      j /= 2;
    }
    for (k = 3; k <= sqrt(j); k = k + 2) {
      while (j % k == 0) {
        s1.insert(k);
        j /= k;
      }
    }
    if (j > 2) s1.insert(j);
    j = b[1];
    while (j % 2 == 0) {
      s1.insert(2);
      j /= 2;
    }
    for (k = 3; k <= sqrt(j); k = k + 2) {
      while (j % k == 0) {
        s1.insert(k);
        j /= k;
      }
    }
    if (j > 2) s1.insert(j);
    for (it = s.begin(); it != s.end(); ++it) {
      for (jt = s1.begin(); jt != s1.end(); jt++) {
        if ((*jt) % (*it) == 0) {
          s3.insert(*it);
        } else if ((*it) % (*jt) == 0)
          s3.insert(*jt);
      }
    }
    s.clear();
    for (i = 2; i < n; ++i) {
      for (it = s3.begin(); it != s3.end(); ++it) {
        if (a[i] % (*it) == 0) s.insert(*it);
        if (b[i] % (*it) == 0) s.insert(*it);
      }
      s3.clear();
      for (it = s.begin(); it != s.end(); ++it) {
        s3.insert(*it);
      }
      s.clear();
    }
    if (s3.size() > 0) {
      for (it = s3.begin(); it != s3.end(); ++it) {
        cout << *it << endl;
        break;
      }
    } else
      cout << "-1\n";
  }
  return 0;
}
