#include <bits/stdc++.h>
using namespace std;
int di[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dj[] = {-1, 0, 1, 0, 1, -1, -1, 1};
int MOD = 1e9 + 7;
int const N = 1e5 + 5;
int n, a[N];
int cost;
bool valid(int c1, int c2) {
  cost = 0;
  int x = a[0], y = a[1];
  if (c1 == 1)
    x++, cost++;
  else if (c1 == 2)
    x--, cost++;
  if (c2 == 1)
    y++, cost++;
  else if (c2 == 2)
    y--, cost++;
  int dif = y - x;
  for (int i = 2; i < n; ++i) {
    if (abs(a[i] - y - dif) > 1) return 0;
    if (abs(a[i] - y - dif) != 0) cost++;
    y += dif;
  }
  return 1;
}
int solv() {
  int ans = 1e9;
  if (n == 1) return 0;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; ++j) {
      if (valid(i, j)) ans = min(cost, ans);
    }
  return (ans == 1e9 ? -1 : ans);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << solv();
}
