#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int M = 8;
const int mod = 1000696969;
int cnt[N], C[N][M], dp[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i < N; i++)
    for (int j = 2 * i; j < N; j += i) cnt[i] += cnt[j];
  C[0][0] = 1;
  for (int i = 1; i < N; i++) {
    C[i][0] = 1;
    for (int j = 1; j < min(i + 1, M); j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
  for (int i = 1; i < M; i++) {
    for (int j = N - 1; j; j--) {
      dp[j] = C[cnt[j]][i];
      for (int k = 2 * j; k < N; k += j) dp[j] = (dp[j] - dp[k]) % mod;
    }
    if (dp[1] != 0) return cout << i, 0;
  }
  cout << -1;
  return 0;
}
