#include <bits/stdc++.h>
using namespace std;
bool first(vector<long long int> a, long long int &c) {
  for (int i = 2; i < a.size(); i++) {
    if (abs(2 * a[i - 1] - a[i] - a[i - 2]) > 1) {
      return false;
    } else {
      if (2 * a[i - 1] != a[i - 2] + a[i]) {
        a[i] = 2 * a[i - 1] - a[i - 2];
        c++;
      }
    }
  }
  return true;
}
int main() {
  long long int n, i, k, j, res, c, a, b;
  res = LONG_LONG_MAX;
  cin >> n;
  vector<long long int> v(n);
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  a = v[0];
  b = v[1];
  for (i = -1; i < 2; i++) {
    for (j = -1; j < 2; j++) {
      c = 0;
      if (i != 0) {
        c++;
      }
      if (j != 0) {
        c++;
      }
      v[0] = a + i;
      v[1] = b + j;
      if (first(v, c)) {
        res = min(res, c);
      }
    }
  }
  if (res == LONG_LONG_MAX) {
    cout << "-1";
  } else {
    cout << res;
  }
}
