#include <bits/stdc++.h>
using namespace std;
int a[2001];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  int cur = a[1];
  for (int i = 2; i <= n; ++i) {
    cur = gcd(cur, a[i]);
  }
  if (cur != 1) {
    cout << -1 << endl;
    return 0;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 1) {
      cnt++;
    }
  }
  int ans = 1e9;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 1) {
      cout << n - cnt << endl;
      return 0;
    }
    cur = a[i];
    for (int j = i; j <= n; ++j) {
      cur = gcd(cur, a[j]);
      if (cur == 1) {
        ans = min(ans, j - i + 1);
        break;
      }
    }
  }
  cout << (ans + n - 2 - cnt) << endl;
}
