#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b != 0) {
    int c = a % b;
    a = b;
    b = c;
  }
  return a;
}
bool isOK(vector<int> &a) {
  int d = a[0];
  for (int i = 1; i < a.size(); ++i) {
    d = gcd(d, a[i]);
  }
  return d == 1;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (!isOK(a)) {
    cout << -1;
    return 0;
  }
  int ed_count = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) {
      ed_count++;
    }
  }
  if (ed_count > 0) {
    cout << n - ed_count;
    return 0;
  }
  int m = INT_MAX;
  for (int i = 0; i < n - 1; ++i) {
    int t = INT_MAX;
    for (int j = i + 1; j < n; ++j) {
      if (gcd(a[i], a[j]) == 1) {
        t = min(t, j - i - 1);
      }
    }
    m = min(m, t);
  }
  if (m > n + 1231) {
    cout << n + 1;
  } else {
    cout << m + n;
  }
  return 0;
}
