#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long oo = 1e13;
long long n, b[3] = {1, 0, -1}, ans = 1e13;
vector<long long> v;
int main() {
  cin >> n;
  if (n == 1) return cout << 0 << endl, 0;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      vector<long long> a = v;
      long long co = 0;
      a[0] += b[i];
      a[1] += b[j];
      int dis = a[1] - a[0];
      co += abs(b[i]) + abs(b[j]);
      for (int x = 2; x < n; ++x) {
        if (dis == a[x] - a[x - 1] + 1) {
          co++;
          a[x]++;
        } else if (dis == a[x] - a[x - 1] - 1) {
          a[x]--;
          co++;
        } else if (dis != a[x] - a[x - 1]) {
          co = 1e13;
          break;
        }
      }
      ans = min(ans, co);
    }
  }
  cout << (ans == 1e13 ? -1 : ans) << endl;
}
