#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b != 0) {
    int c = a % b;
    a = b;
    b = c;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1) {
      ++cnt;
    }
  }
  if (cnt > 0) {
    cout << n - cnt;
    return 0;
  }
  int d = n;
  for (int i = 0; i < n; ++i) {
    int cur = a[i];
    for (int j = i + 1; j < n; ++j) {
      cur = gcd(cur, a[j]);
      if (cur == 1) {
        d = min(d, j - i);
        break;
      }
    }
  }
  if (d == n) {
    cout << -1;
  } else {
    cout << n + d - 1;
  }
  return 0;
}
