import java.io.*;
import java.util.*;
public class Main{
public static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter stdOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static final int N = 100010;
public static int n;
public static int[] a = new int[N];
public static Node[] tree = new Node[4 * N];
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void built(int u, int l, int r) {
if(l == r) tree[u] = new Node(l, r, a[l]);
else {
tree[u] = new Node(l, r, 0);
int mid = (l + r) >> 1;
built(u << 1, l, mid);
built(u << 1 | 1, mid+1, r);
tree[u].gcdValue = gcd(tree[u << 1].gcdValue, tree[u << 1 | 1].gcdValue);
}
}
public static boolean check(int len) {
for(int i = 1; i <= n - len + 1; i++) {
int j = i + len - 1;
if(query(1, i, j) == 1) return true;
}
return false;
}
public static int query(int u, int l, int r) {
if(tree[u].l >= l && tree[u].r <= r) return tree[u].gcdValue;
int gcdValue1 = 0; int gcdValue2 = 0;
int mid = (tree[u].l + tree[u].r) >> 1;
if(l <= mid) gcdValue1 = query(u << 1, l, r);
if(r >= mid + 1) gcdValue2 = query(u << 1 | 1, l, r);
if(gcdValue1 == 0 || gcdValue2 == 0) return Math.max(gcdValue1, gcdValue2);
return gcd(gcdValue1, gcdValue2);
}
public static void main(String[] args) throws IOException{
n = Integer.parseInt(stdIn.readLine());
String[] sp = stdIn.readLine().split(" ");
int numOf1 = 0;
for(int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(sp[i-1]);
if(a[i] == 1) numOf1++;
}
if(numOf1 != 0) {
stdOut.println(n - numOf1); stdOut.flush();
return;
}
built(1, 1, n);
if(!check(n)) {
stdOut.println("-1"); stdOut.flush();
return;
}
int l = 1; int r = n;
while(l < r) {
int mid = (l + r) >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
stdOut.println(l - 1 + n - 1);
stdOut.flush();
}
}
class Node{
int l; int r; int gcdValue;
public Node(int l, int r, int gcdValue) {
this.l = l;
this.r = r;
this.gcdValue = gcdValue;
}
}