#include <bits/stdc++.h>
using namespace std;
int toap(vector<int> &b, int a, int d) {
  int tochange = 0;
  int cur = a;
  for (auto x : b) {
    int dif = std::abs(x - cur);
    if (dif == 1) {
      tochange++;
    } else if (dif > 1) {
      return b.size() + 1;
    }
    cur += d;
  }
  return tochange;
}
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  int min_dist = n + 1;
  for (int f = -1; f <= 1; ++f) {
    for (int s = -1; s <= 1; ++s) {
      min_dist = min(min_dist, toap(b, b[0] + f, b[1] + s - b[0] - f));
    }
  }
  if (min_dist <= n) {
    cout << min_dist << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
