#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
int a[2010];
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  int n, count = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == 1) ++count;
  }
  if (count) {
    printf("%d", n - count);
  } else {
    int t = INF;
    int i, j;
    for (i = 1; i <= n; ++i) {
      int x = a[i];
      for (j = i + 1; j <= n; ++j) {
        x = gcd(x, a[j]);
        if (x == 1) {
          t = min(t, j - i + 1);
          break;
        }
      }
    }
    if (t == INF) {
      puts("-1");
    } else {
      printf("%d\n", t - 1 + n - 1);
    }
  }
  return 0;
}
