#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
long long int dx[] = {0, 1, -1};
long long int dy[] = {0, 1, -1};
void solve() {
  long long int n;
  cin >> n;
  long long int ans = 1000000007;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (n <= 2) {
    cout << 0;
    return;
  }
  for (long long int i = 0; i < 3; i++) {
    for (long long int j = 0; j < 3; j++) {
      long long int f = a[0] + dx[i];
      long long int s = a[1] + dy[j];
      long long int dif = s - f;
      long long int sum = abs(dx[i]) + abs(dy[j]);
      long long int pre = s;
      for (long long int k = 2; k < n; k++) {
        long long int have = pre + dif;
        if (a[k] == have) {
        } else if (abs(a[k] - have) <= 1)
          sum++;
        else {
          sum = 1000000007;
          break;
        }
        pre = have;
      }
      ans = min(ans, sum);
    }
  }
  if (ans == 1000000007) ans = -1;
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
