#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
using namespace std;
const int maxn = 1e3+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, a[maxn];
int p[maxn];
int curr = 0;
void check()
{
long long ans = a[1] + p[1];
for (int i = 2; i <= n; ++ i)
{
ans = __gcd(ans, 1LL * a[i]+p[i]);
}
if(ans == 1)
{
cout << curr << endl;
exit(0);
}
}
void gen(int pos, int lft)
{
if(pos == n+1)
{
check();
return;
}
for (int i = lft; i >= 0; -- i)
{
p[pos] = i;
gen(pos+1, lft - i);
}
}
int main()
{
speed();
cin >> n;
for (int i = 1; i <= n; ++ i)
cin >> a[i];
for (int ans = 0; ans <= 30; ++ ans)
{
curr = ans;
gen(1, ans);
}
cout << 11 <<endl;
return 0;
}