#include <bits/stdc++.h>
using namespace std;
int n, m, q, h, k;
int flag, tmp;
int ans, mxm, mnm;
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%d", &n);
  int a[n];
  int cnt1 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) cnt1++;
  }
  flag = 0;
  ans = n;
  for (int i = 0; i < n - 1; i++) {
    tmp = a[i];
    for (int j = i + 1; j < n; j++) {
      tmp = gcd(tmp, a[j]);
      if (tmp == 1) {
        flag = 1;
        ans = min(ans, j - i);
        break;
      }
    }
  }
  if (cnt1)
    printf("%d", n - cnt1);
  else if (flag)
    printf("%d", ans + n - 1);
  else
    printf("-1");
  return 0;
}
