#include <bits/stdc++.h>
using namespace std;
int n, a[2002], nr;
int gcd(int a, int b) {
  int r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int gcdi = 0, cnt1 = 0;
  for (int i = 1; i <= n; i++) {
    gcdi = gcd(gcdi, a[i]);
    if (a[i] == 1) cnt1 = cnt1 + 1;
  }
  if (gcdi > 1)
    cout << "-1";
  else {
    if (cnt1 > 0)
      cout << n - cnt1;
    else {
      int lmin = n + 1;
      for (int i = 1; i < n; i++) {
        gcdi = a[i];
        for (int j = i + 1; j <= n; j++) {
          gcdi = gcd(gcdi, a[j]);
          if (gcdi == 1 and j - i + 1 < lmin) lmin = j - i + 1;
        }
      }
      cout << n - 1 + lmin - 1;
    }
  }
  return 0;
}
