#include <bits/stdc++.h>
using namespace std;
int gcd(int num1, int num2) {
  if (num2 == 0) return num1;
  return gcd(num2, num1 % num2);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int _gcd = a[0];
  for (int i = 1; i < n; i++) {
    _gcd = gcd(_gcd, a[i]);
  }
  if (_gcd != 1) {
    cout << -1 << endl;
    return 0;
  }
  int num_ones = 0;
  for (int x : a) {
    if (x == 1) num_ones++;
  }
  if (num_ones >= 1) {
    cout << n - num_ones << endl;
    return 0;
  }
  int min_steps = INT_MAX;
  for (int start = 0; start < (n - 1); start++) {
    int ansr = a[start], num_steps = 0;
    for (int stop = start + 1; stop < n; stop++) {
      num_steps++;
      ansr = gcd(ansr, a[stop]);
      if (ansr == 1) break;
    }
    if (ansr == 1) min_steps = min(min_steps, num_steps);
  }
  cout << min_steps + n - 1 << endl;
  return 0;
}
