#include <bits/stdc++.h>
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, count_one = 0, isdealt = 0;
  long long int num[2005];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &num[i]);
  for (int i = 0; i < n; i++)
    if (num[i] == 1) {
      isdealt = 1;
      count_one++;
    }
  if (isdealt) {
    printf("%d", n - count_one);
    return 0;
  }
  for (int i = 1; i <= n - 1; i++)
    for (int j = 0; j < n - i; j++) {
      num[j] = gcd(num[j], num[j + 1]);
      if (num[j] == 1) {
        printf("%d", i + n - 1);
        return 0;
      }
    }
  printf("-1");
  return 0;
}
