#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 998244353;
const int up = 300000;
inline long long quickpow(long long x, int k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * x % P;
    x = x * x % P;
    k >>= 1;
  }
  return res;
}
int n;
long long jie[601000], jieni[601000];
int pri[601000], pcnt, mu[601000];
bool depri[601000];
int bin[601000], cnt[601000];
inline void init() {
  depri[1] = true;
  mu[1] = 1;
  for (int i = 2; i <= up; ++i) {
    if (!depri[i]) pri[++pcnt] = i, mu[i] = -1;
    for (int j = 1; j <= pcnt && i * pri[j] <= up; ++j) {
      depri[i * pri[j]] = true;
      mu[i * pri[j]] = mu[i] * (-1);
      if (i % pri[j] == 0) {
        mu[i * pri[j]] = 0;
        break;
      }
    }
  }
  jie[0] = jieni[0] = 1;
  for (int i = 1; i <= up; ++i) jie[i] = jie[i - 1] * i % P;
  jieni[up] = quickpow(jie[up], P - 2);
  for (int i = up - 1; i; --i) jieni[i] = jieni[i + 1] * (i + 1) % P;
  for (int i = 1; i <= up; ++i) {
    for (int d = i; d <= up; d += i) {
      cnt[i] += bin[d];
    }
  }
}
inline long long get_c(int n, int m) {
  if (n < 0 || m < 0 || n - m < 0) return 0;
  return jie[n] * jieni[m] % P * jieni[n - m] % P;
}
long long g[601000];
inline void work(int k) {
  long long res = 0;
  for (int d = 1; d <= up; ++d) {
    res = (res + get_c(cnt[d], k) * mu[d] + P) % P;
  }
  res = (res % P + P) % P;
  if (res) {
    printf("%d\n", k);
    exit(0);
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    int x;
    read(x);
    ++bin[x];
    if (x == 1) {
      puts("1");
      return 0;
    }
  }
  init();
  for (int i = 1; i <= 7; ++i) work(i);
  puts("-1");
  return 0;
}
