#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
long long fpow(long long x, long long y, long long p = 1000000007) {
  x = x % p;
  long long sum = 1;
  while (y) {
    if (y & 1) sum = sum * x;
    sum %= p;
    y = y >> 1;
    x = x * x;
    x %= p;
  }
  return sum;
}
long long fact[1005] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < 1005; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
  if (r > n) return 0;
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[r], 1000000007 - 2))) % 1000000007;
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long npr(long long n, long long r) {
  if (r > n) return 0;
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
bool vis[1005] = {0};
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (n <= 2) {
    cout << 0 << endl;
    return;
  }
  int ans = oo;
  for (int i : {-1, 0, +1}) {
    for (int j : {-1, 0, +1}) {
      int diff = (a[1] + j) - (a[0] + i);
      int cnt = 0;
      if (i != 0) cnt++;
      if (j != 0) cnt++;
      long long tu = a[0] + i + diff;
      bool pos = true;
      for (int k = 2; k < n; ++k) {
        tu += diff;
        if (abs(a[k] - tu) == 0) continue;
        if (abs(a[k] - tu) == 1) {
          cnt++;
          continue;
        }
        pos = false;
      }
      if (pos) ans = min(ans, cnt);
    }
  }
  if (ans == oo)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
}
