#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2000 + 100;
const int oo = 1e9;
int N;
int a[NMAX];
int gcd(int a, int b) {
  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
void Process() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  int uc = a[1];
  for (int i = 2; i <= N; i++) uc = gcd(uc, a[i]);
  if (uc > 1) {
    printf("-1");
    return;
  }
  int cnt1 = 0;
  for (int i = 1; i <= N; i++)
    if (a[i] == 1) cnt1++;
  if (cnt1 > 0) {
    printf("%d", N - cnt1);
    return;
  }
  int res = oo;
  for (int i = 1; i <= N; i++) {
    int uc = a[i];
    for (int j = i; j <= N; j++) {
      uc = gcd(uc, a[j]);
      if (uc == 1) res = min(res, (j - i) + (N - 1));
    }
  }
  printf("%d", res);
}
int main() {
  Process();
  return 0;
}
