#include <bits/stdc++.h>
using namespace std;
void cp() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
bool compare(long long a, long long b) { return a > b; }
int main() {
  cp();
  {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    };
    long long dx[3] = {1, 0, -1};
    long long dy[3] = {
        -1,
        0,
        1,
    };
    if (n == 1 || n == 2)
      cout << "0";
    else {
      long long ans = INT_MAX;
      bool z = 0;
      for (long long i = 0; i < 3; i++) {
        for (long long j = 0; j < 3; j++) {
          bool k = 0;
          long long an = 0;
          long long b[n];
          for (long long i = 0; i < n; i++) b[i] = a[i];
          b[0] += (dx[i]);
          b[1] += (dy[j]);
          an = an + abs(dx[i]) + abs(dy[j]);
          long long d = b[1] - b[0];
          for (long long h = 2; h < n; h++) {
            long long j = abs(b[h - 1] + d - a[h]);
            b[h] = b[h - 1] + d;
            if (j == 0) {
            } else if (j == 1) {
              an++;
            } else {
              k = 1;
              break;
            }
          }
          if (k == 0) {
            z = 1;
            ans = min(ans, an);
          }
        }
      }
      if (z == 0)
        cout << "-1";
      else {
        cout << ans;
      }
    }
  }
}
