#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int MAXN = 2123;
int n, v[MAXN];
int main() {
  scanf("%d", &n);
  int nn = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    if (v[i] != 1) nn++;
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int g = v[i];
    for (int j = i; j < n; j++) {
      g = gcd(g, v[j]);
      if (g == 1) {
        int l = j - i + 1;
        if (l == 1)
          ans = min(nn, ans);
        else
          ans = min((l - 1) + (nn - 1), ans);
        break;
      }
    }
  }
  if (ans == INT_MAX) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
  return 0;
}
