#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int g = arr[0];
  for (int i = 1; i < n; i++) {
    g = gcd(g, arr[i]);
  }
  if (g != 1) {
    cout << -1 << endl;
    return 0;
  }
  int ext = INT_MAX;
  for (int i = 0; i < n - 1; i++) {
    g = arr[i];
    if (g == 1) {
      ext = 0;
      break;
    }
    for (int j = i + 1; j < n; j++) {
      g = gcd(g, arr[j]);
      if (g == 1) {
        ext = min(ext, j - i);
        break;
      }
    }
  }
  if (ext == INT_MAX) {
    cout << 0 << endl;
    return 0;
  }
  if (ext == 0) ext++;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) ext--;
  }
  cout << n - 1 + ext << endl;
  return 0;
}
