Problem: Janusz is a businessman. He owns a company "Januszex", which produces games for teenagers. Last hit of Januszex was a cool one-person game "Make it one". The player is given a sequence of n integers a_i.

It is allowed to select any subset of them, and the score is equal to the greatest common divisor of selected elements. The goal is to take as little elements as it is possible, getting the score 1. Now Janusz wonders, for given sequence, how much elements should the player choose?

Input

The first line contains an only integer n (1 ≤ n ≤ 300 000) — the number of integers in the sequence.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000).

Output

If there is no subset of the given sequence with gcd equal to 1, output -1.

Otherwise, output exactly one integer — the size of the smallest subset with gcd equal to 1.

Examples

Input

3
10 6 15


Output

3


Input

3
2 4 6


Output

-1


Input

7
30 60 21 42 70 15 30


Output

3

Note

In the first example, selecting a subset of all numbers gives a gcd of 1 and for all smaller subsets the gcd is greater than 1.

In the second example, for all subsets of numbers the gcd is at least 2. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 300007;
const int IT = 500000;
struct xorshift {
  unsigned x, y, z, w;
  xorshift() : x(123456789), y(328932), z(7777777), w(898329832) {}
  unsigned dsljhfdskjfdshkjfds() {
    unsigned t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = w ^ (w >> 19) ^ t ^ (t >> 8);
  }
  unsigned dsljhfdskjfdshkjfds(unsigned a) { return dsljhfdskjfdshkjfds() % a; }
  int dsljhfdskjfdshkjfds(int a, int b) {
    return a + dsljhfdskjfdshkjfds(b - a + 1);
  }
} rng;
int n, a[N], g;
bool have[N];
int i1, i2, i3, i4, i5, i6;
int dsljhfdskjfdshkjfds(int a, int b) { return rng.dsljhfdskjfdshkjfds(a, b); }
int gcd(int a, int b) {
  int r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int gcd(int a, int b, int c) { return gcd(a, gcd(b, c)); }
int gcd(int a, int b, int c, int d) { return gcd(gcd(a, b), gcd(c, d)); }
int gcd(int a, int b, int c, int d, int e) {
  return gcd(gcd(a, b, c), gcd(d, e));
}
int gcd(int a, int b, int c, int d, int e, int f) {
  return gcd(gcd(a, b), gcd(c, d), gcd(e, f));
}
bool try2() {
  int i;
  for (i = 1; i + 1 <= n; i++) {
    if (gcd(a[i], a[i + 1]) == 1) return true;
  }
  if (n <= 1000) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        if (gcd(a[i1], a[i2]) == 1) return true;
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 1);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n);
      if (gcd(a[i1], a[i2]) == 1) return true;
    }
  }
  return false;
}
bool try3() {
  int i;
  for (i = 1; i + 2 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2]) == 1) return true;
  }
  if (n <= 70) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          if (gcd(a[i1], a[i2], a[i3]) == 1) return true;
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 2);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 1);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n);
      if (gcd(a[i1], a[i2], a[i3]) == 1) return true;
    }
  }
  return false;
}
bool try4() {
  int i;
  for (i = 1; i + 3 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3]) == 1) return true;
  }
  if (n <= 30) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            if (gcd(a[i1], a[i2], a[i3], a[i4]) == 1) return true;
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 3);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 2);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 1);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4]) == 1) return true;
    }
  }
  return false;
}
bool try5() {
  int i;
  for (i = 1; i + 4 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3], a[i + 4]) == 1) return true;
  }
  if (n <= 15) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            for (i5 = i4 + 1; i5 <= n; i5++) {
              if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5]) == 1) return true;
            }
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 4);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 3);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 2);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n - 1);
      i5 = dsljhfdskjfdshkjfds(i4 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5]) == 1) return true;
    }
  }
  return false;
}
bool try6() {
  int i;
  for (i = 1; i + 5 <= n; i++) {
    if (gcd(a[i], a[i + 1], a[i + 2], a[i + 3], a[i + 4], a[i + 5]) == 1)
      return true;
  }
  if (n <= 10) {
    for (i1 = 1; i1 <= n; i1++) {
      for (i2 = i1 + 1; i2 <= n; i2++) {
        for (i3 = i2 + 1; i3 <= n; i3++) {
          for (i4 = i3 + 1; i4 <= n; i4++) {
            for (i5 = i4 + 1; i5 <= n; i5++) {
              for (i6 = i5 + 1; i6 <= n; i6++) {
                if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5], a[i6]) == 1)
                  return true;
              }
            }
          }
        }
      }
    }
  } else {
    for (i = 1; i <= IT; i++) {
      i1 = dsljhfdskjfdshkjfds(1, n - 5);
      i2 = dsljhfdskjfdshkjfds(i1 + 1, n - 4);
      i3 = dsljhfdskjfdshkjfds(i2 + 1, n - 3);
      i4 = dsljhfdskjfdshkjfds(i3 + 1, n - 2);
      i5 = dsljhfdskjfdshkjfds(i4 + 1, n - 1);
      i6 = dsljhfdskjfdshkjfds(i5 + 1, n);
      if (gcd(a[i1], a[i2], a[i3], a[i4], a[i5], a[i6]) == 1) return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    have[a[i]] = true;
  }
  if (have[1]) {
    printf("1\n");
    return 0;
  }
  for (i = 1; i <= 300000; i++)
    if (have[i]) {
      for (j = i + i; j <= 300000; j += i) {
        have[j] = false;
      }
    }
  n = 0;
  for (i = 1; i <= 300000; i++)
    if (have[i]) {
      a[++n] = i;
    }
  for (i = 1; i <= n; i++) {
    g = gcd(g, a[i]);
  }
  if (g > 1) {
    printf("-1\n");
    return 0;
  }
  if (try2()) {
    printf("2\n");
  } else if (try3()) {
    printf("3\n");
  } else if (try4()) {
    printf("4\n");
  } else if (try5()) {
    printf("5\n");
  } else if (try6()) {
    printf("6\n");
  } else {
    printf("7\n");
  }
  return 0;
}