#include <bits/stdc++.h>
using namespace std;
typedef struct Link_List {
  struct Link_List *next, *last;
  int a;
} ll;
void insert(ll* head, int value) {
  if (value < 2) return;
  ll* now = head;
  while (now->next != NULL && now->next->a < value) {
    now = now->next;
  }
  if (now->next != NULL && now->next->a == value) return;
  ll* p;
  p = new ll;
  p->a = value;
  p->last = now;
  p->next = now->next;
  if (p->next != NULL) p->next->last = p;
  now->next = p;
  return;
}
void del(ll* now) {
  now->last->next = now->next;
  if (now->next != NULL) now->next->last = now->last;
  free(now);
  return;
}
int main() {
  int i, n, x[150001], y[150001];
  int a[90000], count = 0;
  ll* head;
  cin >> n;
  cin >> x[0] >> y[0];
  head = new ll;
  head->a = 0;
  head->next = NULL;
  for (i = 2; i <= sqrt(x[0] > y[0] ? x[0] : y[0]); i++) {
    if (x[0] % i == 0) {
      insert(head, i);
      insert(head, x[0] / i);
    }
    if (y[0] % i == 0) {
      insert(head, i);
      insert(head, y[0] / i);
    }
  }
  insert(head, x[0]);
  insert(head, y[0]);
  ll* now = head;
  for (i = 1; i < n; i++) {
    cin >> x[i] >> y[i];
    if (x[i] == x[i - 1] && y[i] == y[i - 1] ||
        x[i] == y[i - 1] && y[i] == x[i - 1])
      continue;
    now = head;
    ll* temp = now->next;
    while (temp != NULL) {
      now = temp;
      temp = now->next;
      if (x[i] % now->a != 0 && y[i] % now->a != 0) {
        del(now);
      }
    }
    if (head->next == NULL) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << head->next->a << endl;
  return 0;
}
