#include <bits/stdc++.h>
using namespace std;
int arr[2001][2001];
int gcd(int a, int b) {
  if (b % a == 0) {
    return (a);
  } else {
    return (gcd(b % a, a));
  }
}
int main() {
  int n, i, len, st, end, cnt = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> arr[i][i];
    if (arr[i][i] == 1) {
      cnt++;
    }
  }
  if (cnt > 0) {
    cout << (n - cnt);
    return 0;
  }
  for (len = 2; len <= n; len++) {
    for (i = 1; i <= n - len + 1; i++) {
      st = i;
      end = i + len - 1;
      arr[st][end] = gcd(arr[st][end - 1], arr[end][end]);
      if (arr[st][end] == 1) {
        cout << (len - 1 + n - 1);
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
