#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
long long a[N], b[N];
int n;
int sub_one() {
  int ans = 1;
  b[2] = a[2] - 1;
  long long cha = b[2] - b[1];
  for (int i = 3; i <= n; i++) {
    if (abs(b[i - 1] + cha - a[i]) > 1)
      return INF;
    else {
      if (a[i] - b[i - 1] == cha) {
        b[i] = a[i];
        continue;
      } else {
        ans++;
        if (a[i] - b[i - 1] == cha + 1)
          b[i] = a[i] - 1;
        else
          b[i] = a[i] + 1;
      }
    }
  }
  return ans;
}
int nochange() {
  int ans = 0;
  b[2] = a[2];
  long long cha = b[2] - b[1];
  for (int i = 3; i <= n; i++) {
    if (abs(b[i - 1] + cha - a[i]) > 1)
      return INF;
    else {
      if (a[i] - b[i - 1] == cha) {
        b[i] = a[i];
        continue;
      } else {
        ans++;
        if (a[i] - b[i - 1] == cha + 1)
          b[i] = a[i] - 1;
        else
          b[i] = a[i] + 1;
      }
    }
  }
  return ans;
}
int add_one() {
  int ans = 1;
  b[2] = a[2] + 1;
  long long cha = b[2] - b[1];
  for (int i = 3; i <= n; i++) {
    if (abs(b[i - 1] + cha - a[i]) > 1)
      return INF;
    else {
      if (a[i] - b[i - 1] == cha) {
        b[i] = a[i];
        continue;
      } else {
        ans++;
        if (a[i] - b[i - 1] == cha + 1)
          b[i] = a[i] - 1;
        else
          b[i] = a[i] + 1;
      }
    }
  }
  return ans;
}
int del() {
  b[1] = a[1];
  int ans = min(min(sub_one(), nochange()), add_one());
  return ans;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n <= 2) {
      printf("0\n");
      continue;
    }
    int ans = INF;
    a[1]--;
    ans = min(ans, del() + 1);
    a[1]++;
    ans = min(ans, del());
    a[1]++;
    ans = min(ans, del() + 1);
    if (ans >= INF) ans = -1;
    printf("%d\n", ans);
  }
}
