#include <bits/stdc++.h>
using namespace std;
int N, av[2003];
void readin() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> av[i];
  }
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void process() {
  int flag = 0;
  for (int i = 1; i <= N; ++i) {
    if (av[i] == 1) {
      flag++;
    }
  }
  if (flag) {
    cout << N - flag << endl;
    return;
  }
  flag = 1;
  int ans = INT_MAX;
  for (int i = 1; i <= N; ++i) {
    int t = av[i];
    for (int j = i + 1; j <= N; ++j) {
      if ((t = gcd(t, av[j])) == 1) {
        ans = min(ans, j - i + N - 1);
        break;
      }
    }
  }
  if (ans == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
int main() {
  readin();
  process();
  return 0;
}
