#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int ara[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &ara[i]);
  }
  vector<int> ans;
  bool matched = false;
  bool again = false;
  if (n < 3) {
    return printf("%d\n", 0), 0;
  }
  int cnt = n + 1;
  for (int x = -1; x < 2; x++) {
    for (int y = -1; y < 2; y++) {
      for (int z = -1; z < 2; z++) {
        ans = {{ara[0] + x, ara[1] + y, ara[2] + z}};
        if (ans[0] - ans[1] == ans[1] - ans[2]) {
          bool matched = true;
          int diff = ans[0] - ans[1];
          for (int i = 3; i < n; i++) {
            bool eitathikase = false;
            for (int j = -1; !eitathikase && j < 2; j++) {
              int present = ara[i] + j;
              if (ans[i - 1] - present == diff) {
                ans.push_back(present);
                eitathikase = true;
                break;
              }
            }
            if (!eitathikase) {
              matched = false;
              break;
            }
          }
          if (matched) {
            int tempcnt = 0;
            for (int i = 0; i < n; i++) {
              if (ans[i] != ara[i]) {
                tempcnt++;
              }
            }
            cnt = min(cnt, tempcnt);
            again = true;
          }
        }
      }
    }
  }
  if (again) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
