#include <bits/stdc++.h>
using namespace std;
int arr[3000];
int min_ = 99999999;
int gcd(int m, int n) {
  if (n < m) {
    int c = n;
    n = m;
    m = c;
  }
  while (m) {
    int c = n % m;
    n = m;
    m = c;
  }
  return n;
}
int flag = 0, eq1flag = 0;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == 1) eq1flag++;
  }
  if (eq1flag) {
    printf("%d\n", n - eq1flag);
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int t = 0; t < n - i - 1; t++) {
      int tmp = gcd(arr[t], arr[t + 1]);
      arr[t] = tmp;
      if (tmp == 1) {
        printf("%d\n", n + i);
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}
