#include <bits/stdc++.h>
using namespace std;
int a[20000], n, cnt, x, y;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) cnt++;
  }
  if (cnt > 0) {
    cout << n - cnt;
    return 0;
  }
  cnt = 0;
  y = 1;
  if (n == 1)
    if (a[0] == 1) {
      cout << 0;
      return 0;
    } else {
      cout << -1;
      return 0;
    }
  bool f = 0;
  while (gcd(a[x], a[y]) != 1) {
    if (x == n - 2 && y == n - 1) {
      f = 1;
      break;
    }
    x++;
    y++;
  }
  x = 0;
  y = 1;
  if (f) {
    while (a[x] == a[y]) {
      x++;
      y++;
    }
    while (gcd(a[x], a[y]) != 1 && y != n) {
      cnt++;
      a[y] = gcd(a[x], a[y]);
      x++;
      y++;
    }
    if (y == n) {
      cout << -1;
      return 0;
    }
  } else {
    cout << n;
    return 0;
  }
  cout << n + cnt;
  return 0;
}
