#include <bits/stdc++.h>
using namespace std;
int n;
long long A[2005];
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  int rangeSize = 100000;
  for (int i = 1; i <= n; i++) {
    long long rangeGCD = A[i];
    for (int j = i; j <= n; j++) {
      rangeGCD = gcd(rangeGCD, A[j]);
      if (rangeGCD == 1) {
        rangeSize = min(rangeSize, j - i + 1);
      }
    }
  }
  if (rangeSize == 100000) {
    cout << -1 << '\n';
  } else {
    int cnt_one = 0;
    for (int i = 1; i <= n; i++) {
      if (A[i] == 1) cnt_one++;
    }
    int minimum;
    if (cnt_one == 0)
      minimum = rangeSize - 1 + n - 1;
    else
      minimum = n - cnt_one;
    cout << minimum << '\n';
  }
  return 0;
}
