#include <bits/stdc++.h>
using namespace std;
int n, satu, length, arr[2000][2000];
bool flag, found;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i][0];
    if (arr[i][0] == 1) {
      flag = true;
      satu++;
    }
  }
  if (flag)
    cout << n - satu;
  else {
    length = 2;
    while (!found && length <= n) {
      for (int i = 0; i <= n - length; i++) {
        arr[i][length - 1] = gcd(arr[i][length - 2], arr[i + length - 1][0]);
        if (arr[i][length - 1] == 1) found = true;
      }
      if (!found) length++;
    }
    if (found)
      cout << n - 2 + length;
    else
      cout << -1;
  }
}
