#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar(), w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * w;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
const int N = 2100;
int a[N], n, ct;
int gcd(int x, int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
const int inf = 1e9 + 7;
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    if (a[i] == 1) ++ct;
  }
  if (ct) {
    cout << n - ct << endl;
    return 0;
  }
  int res = inf;
  for (int i = 1; i <= n; ++i) {
    int t = 0;
    for (int j = i; j <= n; ++j) {
      t = gcd(t, a[j]);
      if (t == 1) {
        res = min(res, j - i + 1);
        break;
      }
    }
  }
  if (res == inf)
    puts("-1");
  else
    writeln(res - 1 + (n - 1));
  return 0;
}
