#include <bits/stdc++.h>
using namespace std;
int num;
int arr[2010];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
int process(int val) {
  for (int i = 1; i <= num - val + 1; i++) {
    int ret = 0;
    for (int j = i; j <= i + val - 1; j++) {
      ret = gcd(ret, arr[j]);
    }
    if (ret == 1) return 1;
  }
  return 0;
}
int main(void) {
  scanf("%d", &num);
  for (int i = 1; i <= num; i++) scanf("%d", arr + i);
  int cnt = 0;
  for (int i = 1; i <= num; i++)
    if (arr[i] == 1) cnt++;
  if (cnt) {
    printf("%d", num - cnt);
    return 0;
  }
  int left = 1, right = num;
  while (left < right) {
    int mid = (left + right) / 2;
    if (process(mid))
      right = mid;
    else
      left = mid + 1;
  }
  if (process(left))
    printf("%d", left + num - 2);
  else
    printf("-1");
  return 0;
}
