#include <bits/stdc++.h>
using namespace std;
int kind[3][2] = {{-1, 1}, {0, 0}, {1, 1}};
int n;
bool make_arithmetic(vector<int> &temp, int &progress) {
  int dif = temp[1] - temp[0];
  for (int i = 2; i < n; ++i) {
    int value = temp[i] - temp[i - 1] - dif;
    if (abs(value) > 1) {
      return false;
    } else {
      switch (value) {
        case -1:
          ++progress;
          ++temp[i];
          break;
        case 1:
          ++progress;
          --temp[i];
          break;
      }
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  vector<int> arrs(n, 0);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arrs[i]);
  }
  int ans = INT_MAX;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      vector<int> temp = arrs;
      temp[0] += kind[i][0];
      temp[1] += kind[j][0];
      int progress = 0;
      progress += kind[i][1];
      progress += kind[j][1];
      if (make_arithmetic(temp, progress)) {
        ans = min(ans, progress);
      }
    }
  }
  if (ans == INT_MAX) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}
