#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return (a % b == 0) ? b : gcd(b, a % b); }
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int dp[n][n];
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[i][i] = a[i];
    if (a[i] == 1) {
      c++;
    }
  }
  if (c > 0) {
    cout << n - c;
  } else {
    bool fl = false;
    for (int len = 2; len <= n; len++) {
      for (int i = 0; i < n - len + 1; i++) {
        int j = i + len - 1;
        dp[i][j] = gcd(dp[i][j - 1], dp[j][j]);
        if (dp[i][j] == 1) {
          cout << n + len - 2;
          fl = true;
          break;
        }
      }
      if (fl) break;
    }
    if (!fl) {
      cout << -1;
    }
  }
}
