#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int inf = 1e9 + 1;
const int Mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int g[N][N], a[N];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == 1) ++cnt;
  }
  int mn = (int)2e3 + 5;
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      g[l][r] = gcd(g[l][r - 1], a[r]);
      if (g[l][r] == 1) mn = min(mn, r - l);
    }
  }
  if (mn == (int)2e3 + 5) return cout << -1, 0;
  if (mn == 0)
    cout << n - cnt;
  else
    cout << mn + n - 1;
  return 0;
}
