#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n), t;
  for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
  int res = 1e9;
  for (int i = 0; i < n; ++i) {
    t = v;
    int g = 0;
    for (int j = i; j < n; ++j) {
      if (i == j)
        g = t[j];
      else
        g = gcd(t[j - 1], t[j]);
      if (g == 1) {
        int cur = j - i;
        if (i != j) {
          if (t[j] == 1)
            t[j - 1] = 1;
          else
            t[j] = g;
        }
        for (int i = j - 1; i >= 0; --i)
          if (t[i] != 1) ++cur;
        for (int i = j + 1; i < n; ++i)
          if (t[i] != 1) ++cur;
        res = min(res, cur);
        break;
      } else
        t[j] = g;
    }
  }
  if (res > 1e8) res = -1;
  if (n == 1 && v[0] == 1) res = 0;
  printf("%d\n", res);
  return 0;
}
