#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long MOD = 1e9 + 7;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y % 2) res = (res * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return res;
}
int n, m;
int a[N];
int ans[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  if (n <= 2)
    puts("0");
  else {
    int dx[] = {-1, 0, 1};
    int ans = INT_MAX;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        int con = (a[0] + dx[i]) - (a[1] + dx[j]);
        int x = a[0] + dx[i];
        int counter = 0;
        int temp = 1;
        for (int k = 0; k < n; ++k) {
          if (a[k] == x) {
            x -= con;
            continue;
          } else if (abs(a[k] - x) == 1) {
            ++counter;
            x -= con;
          } else {
            temp = 0;
            break;
          }
        }
        if (temp) ans = min(ans, counter);
      }
    }
    if (ans == INT_MAX)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}
