#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
long long n, a[1000000], cnt, d[2010][2010], x, y = 10000000, m;
int ans = 200000;
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;
  }
  d[0][0] = a[0];
  for (int i = 0; i < n; i++) {
    d[i][i] = a[i];
    bool z = 0;
    for (int j = i; j < n && z == 0; j++) {
      {
        x = a[j + 1];
        y = d[i][j];
        while (x > 0 && y > 0)
          if (x > y)
            x = x % y;
          else
            y = y % x;
        d[i][j + 1] = max(x, y);
        if (max(x, y) == 1) {
          ans = min(ans, j + 1 - i);
          z = 1;
        }
      }
    }
  }
  if (ans == 200000)
    cout << -1;
  else
    cout << ans + n - 1;
  return 0;
}
