#include <bits/stdc++.h>
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
const int maxn = 1e5 + 50;
const int inf = 0x3f3f3f3f;
int n;
int b[maxn], c[maxn], dif;
int res = inf;
int cnt = 0;
bool dfs(int o, int d) {
  if (abs(b[o] - d) > 1) return 0;
  if (b[o] != d) cnt++;
  if (o == n)
    return 1;
  else
    return dfs(o + 1, d + dif);
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(b[i]);
  }
  if (n == 2 || n == 1) return puts("0"), 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int st1 = b[1] + i;
      int st2 = b[2] + j;
      cnt = 0;
      if (i) cnt++;
      if (j) cnt++;
      dif = st2 - st1;
      bool f = dfs(3, st2 + dif);
      if (f) res = min(res, cnt);
    }
  }
  printf("%d\n", res == inf ? -1 : res);
  return 0;
}
