#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2001;
int v[NMAX];
int cmmdc(int a, int b) {
  int r = a % b;
  while (r) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main() {
  int n, i, k, ok, flag;
  scanf("%d", &n);
  scanf("%d", &v[1]);
  ok = v[1];
  flag = (v[1] == 1);
  for (i = 2; i <= n; i++) {
    scanf("%d", &v[i]);
    if (v[i] == 1) flag++;
    ok = cmmdc(ok, v[i]);
  }
  if (ok > 1)
    printf("-1\n");
  else if (flag == 0) {
    k = 2, ok = 0;
    while (!ok) {
      for (i = 1; i <= n - k + 1; i++) {
        v[i] = cmmdc(v[i], v[i + 1]);
        if (v[i] == 1) ok = 1;
      }
      k++;
    }
    k--;
    printf("%d\n", n + k - 2);
  } else
    printf("%d\n", n - flag);
  return 0;
}
