#include <bits/stdc++.h>
using namespace std;
unsigned long long solve(unsigned long long a, unsigned long long b,
                         unsigned long long step, unsigned long long* seq,
                         unsigned long long n) {
  unsigned long long cnt = 0;
  unsigned long long start;
  if (seq[0] <= seq[n - 1]) {
    start = a;
  } else {
    start = b;
    step = -step;
  }
  for (unsigned long long i = 0; i < n; ++i) {
    unsigned long long c = seq[i], d = start + i * step;
    if (c != d) {
      unsigned long long diff;
      diff = (c > d) ? c - d : d - c;
      if (diff == 1) {
        cnt++;
      } else {
        return n + 1;
      }
    }
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long n;
  cin >> n;
  unsigned long long seq[n];
  for (unsigned long long i = 0; i < n; ++i) cin >> seq[i];
  if (n <= 2) {
    cout << 0 << "\n";
    return 0;
  }
  unsigned long long start = seq[0];
  unsigned long long end = seq[n - 1];
  if (end < start) {
    unsigned long long tmp = end;
    end = start;
    start = tmp;
  }
  unsigned long long ans = n + 1;
  ans = min(ans, solve(start - 1, end, (end - start + 1) / (n - 1), seq, n));
  ans = min(ans, solve(start, end + 1, (end - start + 1) / (n - 1), seq, n));
  ans =
      min(ans, solve(start - 1, end + 1, (end - start + 2) / (n - 1), seq, n));
  ans = min(ans, solve(start + 1, end, (end - start - 1) / (n - 1), seq, n));
  ans = min(ans, solve(start, end - 1, (end - start - 1) / (n - 1), seq, n));
  ans =
      min(ans, solve(start + 1, end - 1, (end - start - 2) / (n - 1), seq, n));
  ans = min(ans, solve(start - 1, end - 1, (end - start) / (n - 1), seq, n));
  ans = min(ans, solve(start + 1, end + 1, (end - start) / (n - 1), seq, n));
  ans = min(ans, solve(start + 1, end + 1, (end - start) / (n - 1), seq, n));
  ans = min(ans, solve(start, end, (end - start) / (n - 1), seq, n));
  if (ans == n + 1)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
