#include <bits/stdc++.h>
using namespace std;
vector<long long> v1;
vector<long long> v2;
int solve(long long val, int m) {
  v2.clear();
  v2.push_back(v1[0]);
  int counter = 0;
  for (int i = 0; i < m; ++i) {
    if (val - (v2[i] - v1[i + 1]) == 1) {
      v2.push_back(v1[i + 1] - 1);
      ++counter;
    } else if (val - (v2[i] - v1[i + 1]) == -1) {
      v2.push_back(v1[i + 1] + 1);
      ++counter;
    } else if (val - (v2[i] - v1[i + 1]) == 0) {
      v2.push_back(v1[i + 1]);
    } else if (val - (v2[i] - v1[i + 1]) != 0) {
      counter = 1000000;
      break;
    }
  }
  return counter;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    long long num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      v1.push_back(num);
    }
    int mn = 1000000;
    long long d = v1[0] - v1[1], first = v1[0];
    mn = min(mn, solve(d, n - 1));
    mn = min(mn, solve(d + 1, n - 1));
    mn = min(mn, solve(d - 1, n - 1));
    v1[0] = first - 1;
    d = v1[0] - v1[1];
    mn = min(mn, solve(d, n - 1) + 1);
    mn = min(mn, solve(d + 1, n - 1) + 1);
    mn = min(mn, solve(d - 1, n - 1) + 1);
    v1[0] = first + 1;
    d = v1[0] - v1[1];
    mn = min(mn, solve(d, n - 1) + 1);
    mn = min(mn, solve(d + 1, n - 1) + 1);
    mn = min(mn, solve(d - 1, n - 1) + 1);
    if (mn == 1000000)
      cout << "-1" << endl;
    else
      cout << mn << endl;
  }
  return 0;
}
