#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long long n, a[2009], g, cnt = 0;
  int len = INT_MAX;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      g = a[i];
    else
      g = gcd(g, a[i]);
    if (a[i] == 1) cnt++;
  }
  if (cnt > 0) {
    cout << (n - cnt) << endl;
    return 0;
  }
  if (g != 1) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    g = a[i];
    for (int j = i + 1; j < n; j++) {
      g = gcd(g, a[j]);
      if (g == 1) len = min(len, (j - i + 1));
    }
  }
  cout << (n + len - 2) << endl;
  return 0;
}
