#include <bits/stdc++.h>
using namespace std;
int n;
int b[100010];
int d[100010];
int change[100010];
int main() {
  scanf("%d\n", &n);
  scanf("%d", &(b[0]));
  for (int i = 1; i < n; i++) {
    scanf("%d", &(b[i]));
    d[i - 1] = b[i] - b[i - 1];
  }
  int minCount = -1;
  int curCount;
  int curD;
  for (int d0 = -1; d0 <= 1; d0++) {
    change[0] = d0;
    for (int d1 = -1; d1 <= 1; d1++) {
      change[1] = d1;
      curD = d[0] + change[1] - change[0];
      curCount = 0;
      if (change[0] != 0) curCount++;
      if (change[1] != 0) curCount++;
      int targetB;
      bool isPossible = true;
      for (int i = 2; i < n; i++) {
        targetB = b[i - 1] + change[i - 1] + curD;
        change[i] = targetB - b[i];
        if (change[i] < -1 || change[i] > 1) {
          isPossible = false;
          break;
        }
        if (change[i] != 0) curCount++;
      }
      if (isPossible) {
        if (minCount == -1 || minCount > curCount) minCount = curCount;
      }
    }
  }
  printf("%d\n", minCount);
  return 0;
}
