#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
#define endl '\n'
using namespace std;
#define mid ((left+right)>>1)
mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
int rint(int a,int b){
int ans=0;
ans=a+(rng()%(b-a+1));
return ans;
}
int gcd(int x,int y){
if(x<y)swap(x,y);
if(y==0)return x;
return gcd(y,x%y);
}
struct Seg{
int n;
vector<int>tree,arr;
void build(int node=1,int left=1,int right=-1){
if(right==-1)right=n-1;
if(left==right){
tree[node]=arr[left];
return;
}
build(node*2,left,mid);
build(node*2+1,mid+1,right);
tree[node]=gcd(tree[node*2],tree[node*2+1]);
}
void init(vector<int>Arr){
arr=Arr;
n=arr.size();
tree.resize(n<<2,0);
build();
}
int l,r;
int qu(int node=1,int left=1,int right=-1){
if(right==-1)right=n-1;
if(left>=l&&right<=r)return tree[node];
if(left>r||right<l)return 0;
return gcd(qu(node*2,left,mid),qu(node*2+1,mid+1,right));
}
int query(int left,int right){
l=left;r=right;
return qu();
}
void up(int node=1,int left=1,int right=-1){
if(right==-1)right=n-1;
if(left==right){
tree[node]=r;
return;
}
if(l>mid)up(node*2+1,mid+1,right);
else up(node*2,left,mid);
tree[node]=gcd(tree[node*2],tree[node*2+1]);
}
void update(int tar,int x){
l=tar;r=x;
if(l>=n||l<1)return;
up();
}
};
int n;
vector<int>arr;
Seg seg;
signed main(){
ios_base::sync_with_stdio(23^23);cin.tie(0);
cin>>n;
arr.resize(n+1,0);
for(int i=1;i<=n;i++){
cin>>arr[i];
}
seg.init(arr);
if(seg.tree[1]==1){
cout<<0<<endl;
return 0;
}
int m=1;
for(;;m++){
bool b=false;
for(int i=0;i<3*(1e4/m);i++){
vector<int>v;
for(int j=0;j<m;j++){
v.pb(rint(1,n));
int ind=v.back();
arr[ind]++;
seg.update(ind,arr[ind]);
if(seg.tree[1]==1)b=true;
}
for(int j=0;j<m;j++){
int ind=v.back();
v.pop_back();
arr[ind]--;
seg.update(ind,arr[ind]);
if(seg.tree[1]==1)b=true;
}
}
if(b)break;
}
cout<<m<<endl;
}