#include <bits/stdc++.h>
int const MAX = 1e5 + 5;
using namespace std;
long long check(long long x, long long y, long long a[], long long n,
                long long k) {
  long long c[n];
  for (long long i = 0; i < n; i++) c[i] = a[i];
  c[0] = x;
  c[1] = y;
  long long d = c[1] - c[0];
  for (long long i = 1; i < n - 1; i++) {
    if (abs(c[i + 1] - c[i] - d) > 1) return LLONG_MAX;
    if (((c[i + 1] - c[i]) - d) == 1) {
      k++;
      c[i + 1]--;
    }
    if (((c[i + 1] - c[i]) - d) == -1) {
      k++;
      c[i + 1]++;
    }
  }
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  if (n <= 2) return cout << 0, 0;
  ;
  long long ans = LLONG_MAX;
  ans = min(ans, check(a[0] + 1, a[1] + 1, a, n, 2));
  ans = min(ans, check(a[0] + 1, a[1], a, n, 1));
  ans = min(ans, check(a[0] + 1, a[1] - 1, a, n, 2));
  ans = min(ans, check(a[0], a[1] + 1, a, n, 1));
  ans = min(ans, check(a[0], a[1], a, n, 0));
  ans = min(ans, check(a[0], a[1] - 1, a, n, 1));
  ans = min(ans, check(a[0] - 1, a[1] + 1, a, n, 2));
  ans = min(ans, check(a[0] - 1, a[1], a, n, 1));
  ans = min(ans, check(a[0] - 1, a[1] - 1, a, n, 2));
  if (ans == LLONG_MAX) return cout << -1, 0;
  ;
  cout << ans;
}
