#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int k = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    k = k * 10 + ch - '0';
    ch = getchar();
  }
  return k * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(int x) {
  write(x);
  puts("");
}
const int N = 2010;
int n, a[N];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  n = read();
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] == 1) cnt++;
  }
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    int p = a[i];
    for (int j = i; j <= n; j++) {
      p = gcd(p, a[j]);
      if (p == 1) ans = min(ans, j - i);
    }
  }
  cnt = max(cnt, 1);
  if (ans < 1e9)
    writeln(ans + (n - cnt));
  else
    puts("-1");
  return 0;
}
