#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
const long long INF = 1e18;
long long n, a[nax], ans = INF;
long long check() {
  long long ret = 0, d = a[1] - a[0], want = a[1] + d;
  for (int i = 2; i < n; i++)
    if (abs(a[i] - want) > 1)
      return INF;
    else
      ret += abs(a[i] - want), want += d;
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int x = -1; x <= 1; x++)
    for (int y = -1; y <= 1; y++) {
      a[0] += x, a[1] += y;
      ans = min(ans, check() + !!x + !!y);
      a[0] -= x, a[1] -= y;
    }
  if (ans == INF) {
    cout << "-1\n";
  } else {
    cout << ans << endl;
  }
}
