#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  scanf("%d", &n);
  int o = 0, g = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] == 1) {
      o++;
    }
    if (i == 0) {
      g = a[i];
    } else {
      g = gcd(g, a[i]);
    }
  }
  if (g != 1) {
    puts("-1");
  } else {
    if (o > 0) {
      printf("%d\n", n - o);
    } else {
      int l = n;
      for (int i = 0; i < n; i++) {
        g = a[i];
        for (int j = i + 1; j < n; j++) {
          g = gcd(g, a[j]);
          if (g == 1) {
            l = min(l, j - i);
            break;
          }
        }
      }
      printf("%d\n", n - 1 + l);
    }
  }
  return 0;
}
