#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1e9 + 7;
int x, n, ans, len, a[N];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) scanf("%d", &a[i]);
  len = n + 1;
  for (int i = (1); i < (n + 1); i++) {
    x = a[i];
    for (int j = (i); j < (n + 1); j++) {
      x = gcd(x, a[j]);
      if (x == 1) {
        len = min(len, j - i);
        break;
      }
    }
  }
  for (int i = (1); i < (n + 1); i++)
    if (a[i] == 1) ans--;
  if (len == 0)
    ans = ans + n;
  else
    ans = ans + n + len - 1;
  if (len == n + 1)
    printf("-1");
  else
    printf("%d", ans);
  return 0;
}
