#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 2e5 + 5;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, w;
vector<long long> a;
long long calc(vector<long long> b) {
  long long d = b[1] - b[0], ct = 0;
  for (int i = 2; i < n; i++) {
    long long x = b[i - 1] + d;
    if (abs(x - b[i]) <= 1)
      ct += abs(x - b[i]);
    else
      return INF;
    b[i] = x;
  }
  return ct;
}
void solve() {
  cin >> n;
  a = vector<long long>(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long res = INF;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      a[0] += i, a[1] += j;
      res = min(res, calc(a) + abs(i) + abs(j));
      a[0] -= i, a[1] -= j;
    }
  }
  if (res > n)
    cout << -1 << " "
         << "\n";
  else
    cout << res << " "
         << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}
