#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int n, a[2010], cnt, flag;
int main() {
  n = read();
  cnt = flag = 0;
  for (register int i = int(0); i <= (int)(n - 1); i++) {
    a[i] = read();
    if (a[i] == 1) cnt++;
  }
  if (cnt) return printf("%d\n", n - cnt), 0;
  for (register int i = int(1); i <= (int)(n - 1); i++) {
    for (register int j = int(0); j <= (int)(n - i); j++) {
      a[j] = gcd(a[j], a[j + 1]);
      if (a[j] == 1) {
        printf("%d\n", i + n - 1);
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  if (!flag) puts("-1");
  return 0;
}
