#include <bits/stdc++.h>
using namespace std;
void SOLVE()
{
int n;
cin >> n;
vector<int> a(n + 10), v[n + 10];
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
continue;
if (__gcd(a[i], a[j]) != 1)
{
v[i].push_back(j);
}
}
}
for (int i = 1; i <= n; i++)
{
if (v[i].size() == 0)
{
cout << -1 << '\n';
return;
}
}
int l = 1, r = 2;
int ans = 1;
while (l < r && r < n - 1)
{
bool ok1 = true, ok2 = true;
for (int i = l; i <= r; i++)
{
auto cnt = upper_bound(v[i].begin(), v[i].end(), r) - lower_bound(v[i].begin(), v[i].end(), l);
if (cnt == 0)
{
ok1 = false;
}
}
for (int i = r + 1; i <= n; i++)
{
auto cnt = upper_bound(v[i].begin(), v[i].end(), n) - lower_bound(v[i].begin(), v[i].end(), r + 1);
if (cnt == 0)
{
ok2 = false;
}
}
if (ok1 && ok2)
{
ans++;
l = r + 1;
r = r + 2;
continue;
}
r++;
}
cout << ans << '\n';
}
auto main() -> signed
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int __ = 1;
// for (cin >> __; __--;)
SOLVE();
return 0;
}