#include <bits/stdc++.h>
using namespace std;
long long n, a[10000], mi = INT_MAX;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long dp[5000][5000];
long long check() {
  int cnt = 0;
  for (int ty = 0; ty < n; ty++) cnt += a[ty] == 1 ? 1 : 0;
  return cnt;
}
int main() {
  memset(dp, 0, sizeof(dp));
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long con = a[0];
  for (int i = 1; i < n; i++) {
    dp[i - 1][i] = gcd(a[i - 1], a[i]);
    if (dp[i - 1][i] == 1) mi = 2;
    con = gcd(con, a[i]);
  }
  if (con != 1)
    cout << -1 << endl;
  else if (n == 1 && a[0] != 1)
    cout << -1 << endl;
  else if (n == 1 && a[0] == 1)
    cout << 0 << endl;
  else {
    if (check() > 0)
      cout << n - check() << endl;
    else {
      for (int i = 0; i < n; i++) {
        for (int j = i + 2; j < n; j++) {
          dp[i][j] = gcd(dp[i][j - 1], a[j]);
          if (dp[i][j] == 1) mi = mi > (j - i + 1) ? j - i + 1 : mi;
        }
      }
      cout << mi + n - 2 << endl;
    }
  }
}
