#include <bits/stdc++.h>
const int MAXN = 2007;
const int INF = 1e9 + 7;
int a[MAXN][MAXN];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int n;
  scanf("%d", &n);
  int cnt1 = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i][i]);
    if (a[i][i] == 1) ++cnt1;
  }
  if (cnt1 != 0) {
    printf("%d\n", n - cnt1);
    return 0;
  }
  int ans = 1e9 + 7;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      a[i][j] = gcd(a[i][j - 1], a[j][j]);
      if (a[i][j] == 1) ans = (ans < j - i ? ans : j - i);
    }
  }
  if (ans == INF)
    printf("-1");
  else
    printf("%d\n", n - 1 + ans);
  return 0;
}
