#include <bits/stdc++.h>
using namespace std;
int T[100005];
int T2[100005];
int n;
int check() {
  int d = T2[1] - T2[0];
  int res = 0;
  for (int i = 2; i < n; i++) {
    int c = T2[i - 1] + d;
    if (abs(c - T[i]) > 1) return -1;
    res += abs(c - T[i]);
    T2[i] = c;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> T[i];
  int ans = 1000000;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      T2[0] = T[0] + i;
      T2[1] = T[1] + j;
      int x = check();
      if (x != -1) ans = min(ans, int(x + abs(i) + abs(j)));
    }
  }
  if (ans >= 1000000)
    cout << "-1\n";
  else
    cout << ans << "\n";
  return 0;
}
