#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = (long long)INF * INF;
int n, a[300100];
int cnt[300100];
int comb[300100][10];
int dp[300100];
bool check(int k) {
  for (int i = (1); i < (300100); i++) dp[i] = comb[cnt[i]][k];
  for (int i = 300100 - 1; i > 0; i--)
    for (int j = 2 * i; j < 300100; j += i) dp[i] -= dp[j];
  return dp[1];
}
int32_t main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = (0); i < (300100); i++) {
    comb[i][0] = 1;
    if (i < 10) comb[i][i] = 1;
    for (int j = (1); j < (min(i, 10)); j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
    }
  }
  cin >> n;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j) continue;
      cnt[j]++;
      cnt[a[i] / j]++;
      if (j * j == a[i]) cnt[j]--;
    }
  }
  for (int k = (1); k < (8); k++) {
    if (check(k)) {
      cout << k << '\n';
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
