#include <bits/stdc++.h>
using namespace std;
int a[2010];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, f = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) f++;
  }
  int g = a[1];
  for (int i = 2; i <= n; i++) g = gcd(g, a[i]);
  if (g != 1) {
    cout << "-1";
    return 0;
  }
  if (f > 0) {
    cout << n - f;
    return 0;
  }
  int r = n - 1 + n - 1;
  for (int i = 1; i <= n; i++) {
    g = a[i];
    for (int j = i + 1; j <= n; j++) {
      g = gcd(g, a[j]);
      if (g == 1) {
        r = min(r, j - i + n - 1);
        break;
      }
    }
  }
  cout << r;
  return 0;
}
