#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
const int mo = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long quickpow(int a, int b) {
  long long ans = 1, pow = a;
  while (b) {
    if (b & 1) ans *= pow;
    pow *= pow;
    b >>= 1;
  }
  return ans;
}
long long a[maxn], b[maxn];
int n;
long long check(int x, int y) {
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1] += x, b[2] += y;
  long long d = b[2] - b[1];
  long long ans = abs(x) + abs(y);
  for (int i = 3; i <= n; i++) {
    if (abs(b[i] - b[i - 1] - d) <= 1) {
      ans += abs(b[i] - b[i - 1] - d);
      b[i] = b[i - 1] + d;
    } else
      return -1;
  }
  return ans;
}
int main() {
  while (~scanf("%d", &n)) {
    long long ans = mo;
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        if (check(i, j) != -1) ans = min(ans, check(i, j));
      }
    }
    if (ans == mo)
      puts("-1");
    else
      printf("%I64d\n", ans);
  }
  return 0;
}
