#include <bits/stdc++.h>
using namespace std;
void kick(long long t) { cout << "Case #" << t << ": "; }
bool valid(long long i, long long j, long long n, long long m) {
  return i >= 0 && i < n && j >= 0 && j < m;
}
bool perfect_square(long long a) {
  long long num = sqrt(a);
  if (num * num == a) return true;
  return false;
}
long long digits(long long n) {
  long long cnt = 0;
  while (n > 0) {
    cnt++;
    n = n / 10;
  }
  return cnt;
}
long long modularExponentiation(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      result = ((result % 1000000007) * (x % 1000000007)) % 1000000007;
    }
    x = ((x % 1000000007) * (x % 1000000007)) % 1000000007;
    n = n / 2;
  }
  return result % 1000000007;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  if (n <= 2) {
    cout << 0 << endl;
    return;
  }
  long long ans = 1e18;
  for (long long i = -1; i < 2; i++) {
    for (long long j = -1; j < 2; j++) {
      long long a = v[0] + i;
      long long last = v[1] + j;
      long long sol = abs(i) + abs(j);
      long long d = last - a;
      for (long long k = 2; k < n; k++) {
        long long diff = v[k] - last;
        if (abs(diff - d) <= 1) {
          sol += abs(diff - d);
          last += d;
        } else {
          sol = 1e18;
          break;
        }
      }
      ans = min(ans, sol);
    }
  }
  if (ans == 1e18)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
