#include <bits/stdc++.h>
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
void pause() {}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int mdx[] = {1, 0, -1};
int mdy[] = {1, 0, -1};
long long arr[200002], arr2[200002];
int main() {
  fast_in_out();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr2[i] = arr[i];
  }
  int ans = 1e9;
  for (int u = 0; u < 3; u++) {
    for (int v = 0; v < 3; v++) {
      for (int i = 0; i < n; i++) arr2[i] = arr[i];
      arr2[0] += mdx[u];
      arr2[1] += mdy[v];
      int dif = arr2[1] - arr2[0], cnt = 0;
      if (mdx[u]) cnt++;
      if (mdy[v]) cnt++;
      for (int i = 2; i < n; i++) {
        if (arr2[i] - arr2[i - 1] == dif)
          continue;
        else if (arr2[i] - arr2[i - 1] == dif + 1) {
          cnt++;
          arr2[i]--;
        } else if (arr2[i] - arr2[i - 1] == dif - 1) {
          cnt++;
          arr2[i]++;
        } else {
          cnt = 1e9;
          break;
        }
      }
      ans = min(ans, cnt);
    }
  }
  if (ans == 1e9) {
    cout << -1 << '\n';
  } else
    cout << ans << '\n';
  pause();
  return 0;
}
