#include <bits/stdc++.h>
using namespace std;
int n, sum;
int a[2010];
int gcd(int x, int y) {
  if (y == 0) return x;
  if (y < x) return gcd(y, x);
  return gcd(x, y % x);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) sum++;
  }
  if (sum) {
    cout << n - sum;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= n - i; j++) {
      a[j] = gcd(a[j], a[j + 1]);
      if (a[j] == 1) {
        cout << i + n - 1;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
