#include <bits/stdc++.h>
using namespace std;
int a[2006];
int Gcd(int m, int n) {
  if (n == 0) return m;
  return Gcd(n, m % n);
}
int main() {
  int n;
  scanf("%d", &n);
  int yi = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) yi++;
  }
  if (yi != 0) {
    printf("%d\n", n - yi);
    return 0;
  }
  int min = 5000;
  for (int i = 0; i < n; i++) {
    int sum = 0, mod = a[i];
    for (int j = i + 1; j < n; j++) {
      mod = Gcd(mod, a[j]);
      sum++;
      if (mod == 1) {
        flag = 1;
        if (sum < min) min = sum;
        break;
      }
    }
  }
  if (flag == 1)
    printf("%d\n", min + n - 1);
  else
    printf("-1\n");
}
