#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  vector<int> nums(n);
  int ones = 0;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    if (nums[i] == 1) ones++;
  }
  if (ones) {
    cout << n - ones << "\n";
    return 0;
  }
  for (int i = 1; i < nums.size(); i++) {
    vector<int> temp = nums;
    for (int j = i; j < nums.size(); j++) {
      temp[j] = gcd(nums[j], nums[j - 1]);
      if (temp[j] == 1) {
        cout << nums.size() - 1 + i << "\n";
        return 0;
      }
    }
    nums = temp;
  }
  cout << -1 << "\n";
}
