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