#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2000 + 5;
int n, a[Nmax], d, ans;
int gcd(int x, int y) {
  if (x == 0) return y;
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  cin >> n;
  d = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    d = gcd(d, a[i]);
  }
  if (d > 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] == 1) {
      ans = 0;
      for (int j = 1; j <= n; ++j)
        if (a[j] != 1) ++ans;
      cout << ans;
      return 0;
    }
  ans = 1 << 30;
  for (int i = 1; i <= n; ++i) {
    d = 0;
    for (int j = i; j <= n; ++j) {
      d = gcd(d, a[j]);
      if (d == 1) {
        ans = min(ans, j - i + n - 1);
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
