#include <bits/stdc++.h>
using namespace std;
long long int n, m, ar[1000005], sum, flag, mn = INT_MAX;
long long int gcd(long long int a, long long int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  for (int i = 1; i <= n; i++)
    if (ar[i] == 1) flag++;
  if (flag) return cout << n - flag, 0;
  for (int i = 1; i <= n; i++) {
    long long int x = 0;
    for (int j = i; j <= n; j++) {
      x = gcd(x, ar[j]);
      if (x == 1) mn = min(mn, (long long int)j - i);
    }
  }
  if (mn == INT_MAX) return cout << -1 << "\n", 0;
  cout << n + mn - 1;
}
