#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int gcd(long long int a, long long int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
signed main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int g = a[0];
  for (long long int i = 1; i < n; i++) g = gcd(g, a[i]);
  long long int cnt = 0;
  for (auto i : a) cnt += (i == 1);
  if (cnt > 0) {
    cout << n - cnt << "\n";
    return 0;
  } else if (g > 1) {
    cout << -1 << "\n";
    return 0;
  }
  long long int ans = 1e15;
  for (long long int i = 0; i < n; i++) {
    g = a[i];
    for (long long int j = i; j < n; j++) {
      g = gcd(g, a[j]);
      if (g == 1) ans = min(ans, n + j - i - 1);
    }
  }
  cout << ans << "\n";
  return 0;
}
