#include <bits/stdc++.h>
using namespace std;
const int N = 300 * 1001, MOD = 1e9 + 7;
int n, a[N], dp[10][N], cnt[N], fac[N], extended[N];
int gcd_extended(int a, int b, long long *x, long long *y) {
  if (!a) {
    *x = 0;
    *y = 1;
    return b;
  }
  long long x1, y1;
  int gcd = gcd_extended(b % a, a, &x1, &y1);
  *y = x1;
  *x = y1 - (b / a) * x1;
  return gcd;
}
int _mul(int a, int b) { return 1LL * a * b % MOD; }
int _sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
void build() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = _mul(fac[i - 1], i);
  long long x, y;
  gcd_extended(fac[N - 1], MOD, &x, &y);
  while (x < 0) x += MOD;
  extended[N - 1] = x;
  for (int i = N - 1; 0 < i; i--) extended[i - 1] = _mul(extended[i], i);
}
int choose(int n, int k) {
  if (k > n || 0 > k) return 0;
  return _mul(_mul(fac[n], extended[k]), extended[n - k]);
}
int main() {
  build();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i < N; i++)
    for (int j = 2 * i; j < N; j += i) cnt[i] += cnt[j];
  for (int i = 1; i < 10; i++) {
    for (int j = N - 1; 0 < j; j--) {
      dp[i][j] = choose(cnt[j], i);
      for (int k = 2; k * j < N; k++) dp[i][j] = _sub(dp[i][j], dp[i][k * j]);
    }
    if (dp[i][1]) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << "-1\n";
}
