#include <bits/stdc++.h>
using namespace std;
int mygcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return mygcd(b, a % b);
}
int main() {
  int n, k, temp, c;
  int count = 0;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) count++;
  }
  if (count > 0) {
    cout << n - count << endl;
    return 0;
  }
  vector<int> dp(n, -1);
  for (int j = 0; j < n; j++) {
    k = j - 1;
    temp = arr[j];
    c = 0;
    while (k >= 0 and temp != 1) {
      temp = mygcd(temp, arr[k]);
      c++;
      k--;
    }
    if (temp == 1) dp[j] = c;
  }
  int mins = INT_MAX;
  for (int j = 0; j < n; j++) {
    if (dp[j] != -1) mins = min(mins, dp[j]);
  }
  if (mins == INT_MAX)
    cout << -1 << endl;
  else
    cout << n - 1 + mins << endl;
}
