#include <bits/stdc++.h>
int a[2010];
int gcd(int, int);
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int flag = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) flag++;
  }
  if (flag) {
    printf("%d", n - flag);
  } else {
    int temp = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
      int c = a[i];
      for (int j = i + 1; j < n; j++) {
        c = gcd(c, a[j]);
        if (c == 1) {
          temp = min(temp, j - i);
          break;
        }
      }
    }
    if (temp != 0x3f3f3f3f)
      printf("%d", temp + n - 1);
    else
      printf("-1");
  }
  return 0;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
