#include <bits/stdc++.h>
using namespace std;
long long int arr[2], arr1[150000], arr2[150000][2], n,
    min1 = 1000000000000, min2, a1, ck, sq, i, j, k;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 2; j++) {
      cin >> arr2[i][j];
    }
    min2 = min(arr2[i][0], arr2[i][1]);
    if (min2 < min1) {
      min1 = min2;
      arr[0] = arr2[i][0];
      arr[1] = arr2[i][1];
    }
  }
  for (i = 0; i < 2; i++) {
    a1 = 0;
    ck = 0;
    min2 = arr[i];
    while ((min2 % 2) == 0) {
      ck = 1;
      min2 /= 2;
    }
    if (ck == 1) {
      arr1[a1] = 2;
      a1++;
    }
    sq = sqrt(min2);
    for (j = 3; j <= sq; j += 2) {
      ck = 0;
      while ((min2 % j) == 0) {
        ck = 1;
        min2 /= j;
      }
      if (ck == 1) {
        arr1[a1] = j;
        a1++;
      }
    }
    if (min2 > 2) {
      arr1[a1] = min2;
      a1++;
    }
    for (j = 0; j < a1; j++) {
      for (k = 0; k < n; k++) {
        if ((arr2[k][0] % arr1[j] != 0) && (arr2[k][1] % arr1[j] != 0)) {
          break;
        }
      }
      if (k == n) {
        cout << arr1[j] << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
