#include <bits/stdc++.h>
using namespace std;
long long x[100005], dp[100005], y[100005], n, df;
long long solve(int ind) {
  if (ind >= n) {
    return 0;
  }
  if (dp[ind] != -1) {
    return dp[ind];
  }
  long long temp = x[ind];
  if (temp - x[ind - 1] == df) {
    return dp[ind] = solve(ind + 1);
  } else if ((temp + 1) - x[ind - 1] == df) {
    x[ind] = temp + 1;
    return dp[ind] = solve(ind + 1) + 1;
  } else if ((temp - 1) - x[ind - 1] == df) {
    x[ind] = temp - 1;
    return dp[ind] = solve(ind + 1) + 1;
  } else {
    return dp[ind] = 1e6;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    y[i] = x[i];
  }
  long long ans = 1e6;
  long long chk[3] = {0, 1, -1};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < n; i++) {
        x[i] = y[i];
      }
      x[0] += chk[i], x[1] += chk[j];
      df = (x[1]) - (x[0]);
      long long c = (bool(i) + bool(j));
      for (int m = 2; m < n; m++) {
        if (x[m] - x[m - 1] == df) {
          continue;
        } else if (x[m] - x[m - 1] == df + 1) {
          x[m]--;
          c++;
          continue;
        } else if (x[m] - x[m - 1] == df - 1) {
          x[m]++;
          c++;
          continue;
        } else {
          c = -1;
          break;
        }
      }
      if (c != -1) {
        ans = min(ans, c);
      }
    }
  }
  (ans < 1e6) ? cout << ans : cout << -1;
  return 0;
}
