#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b > a) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int cnt = -1;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] == 1) ++cnt;
  }
  int min_dist = 1e9, val;
  for (int i = 0; i < n; ++i) {
    val = v[i];
    for (int j = i; j < n; ++j) {
      val = gcd(val, v[j]);
      if (val == 1) min_dist = min(min_dist, j - i);
    }
  }
  cout << (min_dist != 1e9 ? min_dist + n - 1 - max(cnt, 0) : -1);
  return 0;
}
