Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....

You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist.

Input

The first line contains integer (1 ≤ n ≤ 100) — the number of geometric progressions. 

Next n lines contain pairs of integers a, b (1 ≤ a, b ≤ 109), that are the first element and the common ratio of the corresponding geometric progression.

Output

If the intersection of all progressions is empty, then print  - 1, otherwise print the remainder of the minimal positive integer number belonging to all progressions modulo 1000000007 (109 + 7).

Examples

Input

2
2 2
4 1


Output

4


Input

2
2 2
3 3


Output

-1

Note

In the second sample test one of the progressions contains only powers of two, the other one contains only powers of three.
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
long long add(long long a, const long long b) {
  a += b;
  if (a >= Mod) a -= Mod;
  return a;
}
long long mul(const long long a, const long long b) {
  return (long long)a * b % Mod;
}
long long power(long long x, long long cs) {
  long long ras = 1;
  while (cs) {
    if (cs & 1ll) ras = mul(ras, x);
    x = mul(x, x);
    cs >>= 1;
  }
  return ras;
}
const long long N = 110, M = 3050;
long long n, m = 0;
long long A[N], B[N], pl[M];
void insert(long long n) {
  long long i;
  for (i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    pl[++m] = i;
    while (n % i == 0) n /= i;
  }
  if (n > 1) pl[++m] = n;
}
struct Comb {
  long long a[M], b[M];
  Comb() {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
  }
} h[N];
Comb build(long long A, long long B) {
  long long i;
  Comb f;
  for (i = 1; i <= m; i++) {
    while (A % pl[i] == 0) f.a[i]++, A /= pl[i];
    while (B % pl[i] == 0) f.b[i]++, B /= pl[i];
  }
  return f;
}
long long bx, by;
long long exgcd(long long a, long long b) {
  if (b == 0) {
    bx = 1;
    by = 0;
    return a;
  }
  long long nx, ny, tmp;
  tmp = exgcd(b, a % b);
  nx = by;
  ny = bx - (a / b) * by;
  bx = nx;
  by = ny;
  return tmp;
}
long long smul(long long a, long long b, long long Mod) {
  return ((a * b - ((long long)((long double)a * b / Mod) * Mod)) % Mod + Mod) %
         Mod;
}
Comb merge(Comb h1, Comb h2) {
  long long i, j, k, cs, x, y, d, der, pd1, pd2, w, now, pd;
  static long long a[M][4];
  Comb f;
  memset(a, 0, sizeof(a));
  pd1 = pd2 = 0;
  for (i = 1; i <= m; i++) {
    a[i][1] = h1.b[i];
    a[i][2] = -h2.b[i];
    a[i][3] = h2.a[i] - h1.a[i];
    if (a[i][1]) pd1 = 1;
    if (a[i][2]) pd2 = 1;
  }
  if (pd1 == 0 && pd2 == 0) {
    for (i = 1; i <= m; i++) {
      if (a[i][3]) {
        puts("-1");
        exit(0);
      }
    }
    for (i = 1; i <= m; i++) f.a[i] = h1.a[i], f.b[i] = 0;
    return f;
  }
  if (pd1 == 0 || pd2 == 0) {
    pd = 0;
    for (i = 1; i <= m; i++) {
      if (a[i][1] + a[i][2]) {
        if (a[i][3] % (a[i][1] + a[i][2]) != 0) {
          puts("-1");
          exit(0);
        }
        now = a[i][3] / (a[i][1] + a[i][2]);
        if (pd == 0)
          w = now, pd = 1;
        else if (now != w) {
          puts("-1");
          exit(0);
        }
      }
    }
    for (i = 1; i <= m; i++) f.a[i] = (pd2 ? h1.a[i] : h2.a[i]), f.b[i] = 0;
    return f;
  }
  for (i = 1; i <= 2; i++) {
    for (j = i + 1; j <= m; j++) {
      if (a[j][i]) {
        for (k = i; k <= 3; k++) swap(a[i][k], a[j][k]);
      }
    }
    if (a[i][i] == 0) continue;
    for (j = i + 1; j <= m; j++) {
      if (i == j) continue;
      while (a[i][i] && a[j][i]) {
        cs = a[j][i] / a[i][i];
        for (k = i; k <= 3; k++) a[j][k] -= cs * a[i][k];
        for (k = i; k <= 3; k++) swap(a[i][k], a[j][k]);
      }
      if (a[i][i] == 0)
        for (k = i; k <= 3; k++) swap(a[i][k], a[j][k]);
    }
  }
  for (i = 1; i <= m; i++) {
    if (a[i][1] == 0 && a[i][2] == 0 && a[i][3] > 0) {
      puts("-1");
      exit(0);
    }
  }
  if (a[2][2] == 0) {
    d = exgcd(a[1][1], a[1][2]);
    if (a[1][3] % d != 0) {
      puts("-1");
      exit(0);
    }
    der = abs(a[1][2] / d);
    bx = smul(bx % der, (a[1][3] / d) % der, der);
    der = abs(a[1][1] / d);
    by = smul(by % der, (a[1][3] / d) % der, der);
    bx = max(bx, (a[1][3] - a[1][2] * by) / a[1][1]);
    for (i = 1; i <= m; i++)
      f.a[i] = h1.a[i] + bx * h1.b[i], f.b[i] = abs(a[1][1] / d * a[1][2]);
    return f;
  } else {
    if (a[1][3] % a[1][1] != 0 || a[2][3] % a[2][2] != 0) {
      puts("-1");
      exit(0);
    } else {
      y = a[2][3] / a[2][2];
      x = (a[1][3] - y * a[1][2]) / a[1][1];
      if (x < 0 || y < 0) {
        puts("-1");
        exit(0);
      }
      for (i = 1; i <= m; i++) f.a[i] = h1.a[i] + x * h1.b[i], f.b[i] = 0;
      return f;
    }
  }
}
long long qry(Comb a) {
  long long ans = 1, i;
  for (i = 1; i <= m; i++) {
    ans = mul(ans, power(pl[i], a.a[i]));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  long long i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> A[i] >> B[i];
    insert(A[i]);
    insert(B[i]);
  }
  sort(pl + 1, pl + m + 1);
  m = unique(pl + 1, pl + m + 1) - pl - 1;
  for (i = 1; i <= n; i++) h[i] = build(A[i], B[i]);
  for (i = n - 1; i >= 1; i--) {
    h[i] = merge(h[i], h[i + 1]);
    for (j = 1; j <= m; j++) {
      if (h[i].a[j] < 0) {
        puts("-1");
        exit(0);
      }
    }
  }
  cout << qry(h[1]);
  return 0;
}
