#include <bits/stdc++.h>
using namespace std;
int a[2050];
int GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int L = 0;
  int Count = N;
  int i;
  int flag = 0;
  for (i = 1; i <= N; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      flag++;
    }
  }
  if (flag) {
    cout << N - flag;
    exit(0);
  }
  while (Count != 1) {
    L++;
    for (i = 1; i < Count; i++) {
      a[i] = GCD(a[i], a[i + 1]);
      if (a[i] == 1) {
        flag = 1;
        break;
      }
    }
    if (flag) break;
    Count--;
  }
  if (flag) {
    cout << N - 1 + L << endl;
  } else
    cout << -1 << endl;
  return 0;
}
