#include <bits/stdc++.h>
using namespace std;
int n;
int t[100010], v[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
    v[i] = t[i];
  }
  if (n == 1) {
    printf("0");
    return 0;
  }
  int answer = 1e9;
  for (int i = -1; i <= 1; i++)
    for (int j = -1; j <= 1; j++) {
      int cur_answer = 0;
      int x = (t[2] + j) - (t[1] + i);
      t[2] = t[2] + j;
      cur_answer = abs(i) + abs(j);
      for (int k = 3; k <= n; k++)
        if (abs((t[k] - t[k - 1]) - x) > 1)
          goto finish;
        else {
          cur_answer += abs((t[k] - t[k - 1]) - x);
          t[k] += (x - (t[k] - t[k - 1]));
        }
      answer = min(answer, cur_answer);
    finish:
      for (int k = 1; k <= n; k++) t[k] = v[k];
    }
  if (answer == 1e9)
    printf("-1");
  else
    printf("%d", answer);
  return 0;
}
