#include <bits/stdc++.h>
using namespace std;
int A[100010];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1, n, i, j;
  cin >> n;
  int cnt = 0;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] == 1) cnt++;
  }
  if (cnt) {
    cout << n - cnt << "\n";
  } else {
    int cur = 0;
    for (i = 0; i < n; i++) cur = gcd(cur, A[i]);
    if (cur != 1) {
      cout << "-1\n";
    } else {
      int mn = n;
      for (i = 0; i < n; i++) {
        cur = A[i];
        for (int j = i + 1; j < n; j++) {
          cur = gcd(cur, A[j]);
          if (cur == 1) {
            mn = min(mn, j - i);
            break;
          }
        }
      }
      cout << mn + n - 1 << "\n";
    }
  }
  return 0;
  return 0;
}
