#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 2e4 + 7;
int a[maxn];
int _gcd(int a, int b) { return a == 0 ? b : _gcd(b % a, a); }
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int minn = INF;
    int flag = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        flag++;
      }
    }
    if (flag) {
      cout << n - flag << endl;
      continue;
    }
    for (int i = 0; i < n; ++i) {
      int gcd = a[i];
      for (int j = i + 1; j < n; j++) {
        gcd = _gcd(gcd, a[j]);
        if (gcd == 1) {
          minn = min(minn, j - i);
          break;
        }
      }
    }
    if (minn == INF) {
      cout << -1 << endl;
    } else {
      cout << minn + n - 1 << endl;
    }
  }
  return 0;
}
