#include <bits/stdc++.h>
int a[2005];
int gcd(int a, int b) {
  if (b) return gcd(b, a % b);
  return a;
}
int min(int a, int b) { return a < b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) cnt++;
  }
  if (cnt) {
    printf("%d", n - cnt);
    return 0;
  }
  int res = 1e9;
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    for (int j = i + 1; j <= n; j++) {
      x = gcd(x, a[j]);
      if (x == 1) {
        res = min(res, j - i + 1);
        break;
      }
    }
  }
  if (res == 1e9)
    printf("-1");
  else
    printf("%d", res - 2 + n);
  return 0;
}
