#include <bits/stdc++.h>
using namespace std;
long long solve(pair<long long, long long> candy, vector<long long> a,
                long long n) {
  a[0] += candy.first;
  a[1] += candy.second;
  long long d = a[1] - a[0];
  long long changes = 0;
  if (candy.first != 0) changes++;
  if (candy.second != 0) changes++;
  for (long long i = 2; i < n; i++) {
    if (a[i] - a[i - 1] == d) continue;
    if (a[i] + 1 - a[i - 1] == d) {
      changes++;
      a[i]++;
      continue;
    }
    if (a[i] - 1 - a[i - 1] == d) {
      changes++;
      a[i]--;
      continue;
    }
    return LLONG_MAX;
  }
  return changes;
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long &x : a) cin >> x;
    if (n == 1 || n == 2) {
      cout << 0;
      continue;
    }
    vector<pair<long long, long long>> candidates = {
        {0, 0},  {0, 1},  {0, -1}, {1, 0},  {1, 1},
        {1, -1}, {-1, 0}, {-1, 1}, {-1, -1}};
    long long ans = LLONG_MAX;
    for (auto c : candidates) ans = min(ans, solve(c, a, n));
    if (ans == LLONG_MAX)
      cout << -1;
    else
      cout << ans;
  }
  return 0;
}
