#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  int z = 0;
  while (y > 0) {
    z = y;
    y = x % y;
    x = z;
  }
  return x;
}
int main() {
  int n;
  cin >> n;
  vector<int> a;
  int ed = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
    if (t == 1) {
      ed += 1;
    }
  }
  if (ed > 0) {
    cout << n - ed;
  } else {
    vector<int> mas;
    int ind = 0;
    for (int l = 0; l < n; l++) {
      int s = a[l];
      for (int r = l + 1; r < n; r++) {
        s = gcd(s, a[r]);
        if (s == 1) {
          ind = 1;
          mas.push_back(r - l);
        }
      }
    }
    if (ind == 0) {
      cout << -1;
    } else {
      int minx = mas[0];
      for (int i = 1; i < mas.size(); i++) {
        if (mas[i] < minx) {
          minx = mas[i];
        }
      }
      cout << n - 1 + minx;
    }
  }
}
