#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b) {
    int tmp = a;
    a = b;
    b = tmp % b;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  int n;
  cin >> n;
  int one = 0;
  vector<int> vec(n), pref_gcd(n), suff_gcd(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    if (vec[i] == 1) {
      one++;
    }
  }
  if (one) {
    cout << n - one;
    return 0;
  }
  int len = 1e9;
  for (int l = 0; l < n; l++) {
    int g = vec[l];
    for (int r = l + 1; r < n; r++) {
      g = gcd(g, vec[r]);
      if (g == 1) {
        len = min(len, r - l);
      }
    }
  }
  if (len == (int)1e9) {
    cout << -1;
    return 0;
  }
  cout << n + len - 1;
  return 0;
}
