#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long exp(long long a, long long b, long long m) {
  if (b == 0) return 1;
  if (b == 1) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
struct query {
  long long l, r, x, id;
};
long long ans[300100];
long long cnt[300100];
vector<long long> d[300100];
long long mark[300100];
long long mu[300100];
long long a[300100];
void crivo() {
  mu[1] = 1;
  vector<long long> primes;
  for (long long i = 2; i < 300100; i++) {
    if (!mark[i]) {
      primes.push_back(i);
      mu[i] = -1;
    }
    for (long long j = 0; j < primes.size() && primes[j] * i < 300100; j++) {
      mark[i * primes[j]] = true;
      if (i % primes[j] == 0) {
        mu[i * primes[j]] = 0;
        break;
      } else {
        mu[i * primes[j]] = -mu[i];
      }
    }
  }
  for (long long i = 1; i < 300100; i++) {
    for (long long j = i; j < 300100; j += i) {
      d[j].push_back(i);
    }
  }
}
void update(long long x, long long v) {
  for (long long i = 0; i < d[x].size(); i++) {
    cnt[d[x][i]] += v;
  }
}
long long coprime(long long x, long long L, long long R) {
  long long r = 0;
  for (long long i = 0; i < d[x].size(); i++) {
    r += cnt[d[x][i]] * mu[d[x][i]];
  }
  return r;
}
long long fat[300100];
long long inv[300100];
long long fat2[300100];
long long inv2[300100];
const long long M = 1e9 + 7;
const long long MM = 1e9 + 9;
long long C(long long r, long long qtd) {
  if (r < qtd) return 0;
  return (fat[r] * inv[r - qtd]) % M;
}
long long C2(long long r, long long qtd) {
  if (r < qtd) return 0;
  return (fat2[r] * inv2[r - qtd]) % MM;
}
long long n;
const long long MAX = 300000;
long long ok(long long x) {
  long long r = 0;
  long long r2 = 0;
  for (long long i = 1; i <= MAX; i++) {
    r2 += mu[i] * C2(cnt[i], x);
    r2 %= MM;
  }
  for (long long i = 1; i <= MAX; i++) {
    r += mu[i] * C(cnt[i], x);
    r %= M;
  }
  return (r != 0) || (r2 != 0);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  crivo();
  fat[0] = inv[0] = 1;
  fat2[0] = inv2[0] = 1;
  for (long long i = 1; i < 300100; i++) {
    fat[i] = (fat[i - 1] * i) % M;
    inv[i] = exp(fat[i], M - 2, M);
    fat2[i] = (fat2[i - 1] * i) % MM;
    inv2[i] = exp(fat2[i], MM - 2, MM);
  }
  long long g = -1;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    update(a[i], 1);
    if (g == -1)
      g = a[i];
    else
      g = gcd(g, a[i]);
  }
  if (g != 1) {
    cout << -1 << "\n";
    return 0;
  }
  for (long long mid = 1; mid <= min(7LL, n); mid++) {
    if (ok(mid)) {
      cout << mid << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
