#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return (a == 0) ? b : gcd(b % a, a); }
int main() {
  int n;
  cin >> n;
  int arr[n + 10];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int g = 0;
  for (int i = 1; i <= n; i++) {
    g = gcd(g, arr[i]);
  }
  if (g != 1) {
    cout << -1 << '\n';
    return 0;
  }
  int oc = 0;
  for (int i = 1; i <= n; i++)
    if (arr[i] == 1) oc++;
  if (oc > 0) {
    cout << n - oc << '\n';
    return 0;
  } else {
    int minl = INT_MAX;
    for (int i = 1; i <= n - 1; i++) {
      int k = arr[i];
      for (int j = i + 1; j <= n; j++) {
        k = gcd(k, arr[j]);
        if (k == 1) {
          minl = min(minl, j - i);
          break;
        }
      }
    }
    cout << n + minl - 1 << '\n';
    return 0;
  }
  return 0;
}
