#include <bits/stdc++.h>
using namespace std;
int pgcd(int a, int b) { return b ? pgcd(b, a % b) : a; }
int n;
int num[2001];
void solve() {
  int d = 0;
  for (int i = 0; i < n; i++)
    if (num[i] != 1) d++;
  if (!d) {
    cout << 0;
    return;
  }
  int tot = 0;
  for (int i = 0; i < n; i++) tot = pgcd(tot, num[i]);
  if (tot != 1) {
    cout << -1;
    return;
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == 1) {
      cout << d;
      return;
    }
  }
  int best = 1e9;
  for (int i = 0; i < n; i++) {
    int j = i;
    bool p = 0;
    int cur = 0;
    int act = num[i];
    while (j - 1 >= 0) {
      j--;
      cur++;
      act = pgcd(act, num[j]);
      if (act == 1) {
        cur += n - 1;
        p = 1;
        break;
      }
    }
    if (p) best = min(best, cur);
    p = 0;
    cur = 0;
    j = i;
    act = num[i];
    while (j + 1 < n) {
      j++;
      cur++;
      act = pgcd(act, num[j]);
      if (act == 1) {
        cur += n - 1;
        p = 1;
        break;
      }
    }
    if (p) best = min(best, cur);
  }
  if (best == (int)1e9) {
    cout << -1;
    return;
  }
  cout << best;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> num[i];
  solve();
}
