#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  if (n <= 2) {
    cout << "0\n";
    return 0;
  }
  int ans = n + 10;
  for (int x = -1; x <= 1; ++x) {
    for (int y = -1; y <= 1; ++y) {
      long long a1 = b[0] + x;
      long long a2 = b[1] + y;
      long long d = a2 - a1;
      int curr = 0;
      if (x) {
        ++curr;
      }
      if (y) {
        ++curr;
      }
      long long pr = a2;
      bool ok = true;
      for (int i = 2; i < n; ++i) {
        long long val = pr + d;
        if (b[i] == val - 1) {
          ++curr;
        } else if (b[i] == val + 1) {
          ++curr;
        } else if (b[i] != val) {
          ok = false;
          break;
        }
        pr = val;
      }
      if (ok) {
        ans = min(ans, curr);
      }
    }
  }
  if (ans > n) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
}
