#include <bits/stdc++.h>
template <typename T>
inline T MIN(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline T MAX(T a, T b) {
  return a > b ? a : b;
}
using namespace std;
void reop() { freopen("input.txt", "r", stdin); }
int a[100001] = {0};
int ans = 0, curans = 0;
bool test(int div, int n, int start) {
  int prev = start;
  for (int i = 2; i < n; ++i) {
    if (a[i] == prev + div)
      prev = a[i];
    else if (a[i] + 1 == prev + div) {
      prev = a[i] + 1;
      curans++;
    } else if (a[i] - 1 == prev + div) {
      prev = a[i] - 1;
      curans++;
    } else
      return false;
  }
  ans = MIN(ans, curans);
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1 || n == 2) {
    cout << 0;
    return 0;
  }
  ans = 1000000007;
  for (int i = -1; i <= 1; ++i) {
    for (int j = -1; j <= 1; ++j) {
      curans = 0;
      int div = a[1] + j - (a[0] + i);
      if (j) curans++;
      if (i) curans++;
      test(div, n, a[1] + j);
    }
  }
  cout << (ans == 1000000007 ? -1 : ans);
  return 0;
}
