#include <bits/stdc++.h>
using namespace std;
int dp[2010][2010], a[2010];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, i, j, ans, mn, cnt;
  scanf("%d", &n);
  cnt = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] == 1) cnt++;
  }
  if (cnt) {
    ans = n - cnt;
  } else {
    mn = 0x3fffffff;
    for (i = 0; i < n; i++) {
      for (j = i; j < n; j++) {
        dp[i][j] = (i == j ? a[i] : gcd(dp[i][j - 1], a[j]));
        if (dp[i][j] == 1) mn = min(mn, j - i);
      }
    }
    if (mn == 0x3fffffff)
      ans = -1;
    else
      ans = mn + n - 1;
  }
  printf("%d\n", ans);
  return 0;
}
