#include<bits/stdc++.h>
using namespace std;
#define maxn 2000+100
int a[maxn];
int b[maxn];
int gcd(int a,int b){
int temp;
if(a<b){
temp=a;
a=b;
b=temp;
}
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
return a;
}
int main(){
int n;
cin>>n;
int i=0;
for(int j=1;j<=n;j++){
scanf("%d",&a[j]);
if(a[j]==1) i++;
}
if(i){
cout<<n-i<<endl;
return 0;
}
int ans=20001;
for(int j=1;j<n;j++){
int t=a[j];
for(int k=j+1;k<=n;k++){
t=gcd(t,a[k]);
if(t==1){
ans=min(ans,k-j);
}
}
}
if(ans==20001) cout<<"-1"<<endl;
else cout<<ans+n-1<<endl;
return 0;
}