#include <bits/stdc++.h>
using namespace std;
const int N = 2005, INF = 0x3f3f3f3f;
int a[N], n, f[N][N];
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
  int i, j, g, k, l, minx = INF, cnt = 0;
  scanf("%d", &n);
  memset(f, 0x3f, sizeof(f));
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[i][i] = a[i];
    if (a[i] == 1) cnt++;
  }
  if (cnt) {
    printf("%d", n - cnt);
    return 0;
  }
  for (i = 1; i < n; i++)
    for (j = i + 1; j <= n; j++) {
      f[i][j] = gcd(max(f[i][j - 1], a[j]), min(f[i][j - 1], a[j]));
      if (f[i][j] == 1) {
        minx = min(minx, j - i);
        break;
      }
    }
  if (minx == INF)
    printf("-1");
  else
    printf("%d", minx + n - 1);
  return 0;
}
