#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int b[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", b + i);
  int flag = 0, ans = n;
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = -1; i <= 1; i++)
    for (int j = -1; j <= 1; j++) {
      int a0 = b[0] + i, an = b[n - 1] + j;
      int ant = 0;
      if (abs(i) == 1) ant++;
      if (abs(j) == 1) ant++;
      if (abs(an - a0) % (n - 1) == 0) {
        int d = (an - a0) / (n - 1);
        int flag1 = 1;
        int pre = a0;
        for (int k = 1; k < n - 1; k++) {
          if (abs(b[k] - (pre + d)) == 1)
            ant++;
          else if (abs(b[k] - (pre + d)) == 0)
            ;
          else {
            flag1 = 0;
            break;
          }
          pre += d;
        }
        if (flag1) {
          flag = 1;
          ans = min(ans, ant);
        }
      }
    }
  if (flag)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
