#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  int min_dist = INF, count_ones = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1) ++count_ones;
  }
  if (count_ones == 0) {
    for (int l = 0; l < n - 1; ++l) {
      int g = a[l];
      for (int r = l + 1; r < n; ++r) {
        g = gcd(g, a[r]);
        if (g == 1) min_dist = min(min_dist, r - l);
      }
    }
    if (min_dist == INF)
      cout << -1 << endl;
    else
      cout << min_dist + n - 1 << endl;
  } else
    cout << n - count_ones << endl;
  return 0;
}
