#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
int a[100010];
int b[100010];
int xx[9] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int yy[9] = {0, 1, -1, 0, 1, -1, 0, 1, -1};
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1 || n == 2) {
    cout << 0 << '\n';
    return;
  }
  int ans = 0x7ffffff, k = 0, ji;
  for (int i = 0; i < 9; i++) {
    k = 0, ji = 0;
    memcpy(b, a, sizeof(a));
    b[1] += xx[i], b[2] += yy[i];
    if (xx[i]) k++;
    if (yy[i]) k++;
    int mi = b[2] - b[1];
    for (int j = 3; j <= n; j++) {
      if (b[j] == b[j - 1] + mi)
        continue;
      else if (b[j] - 1 == b[j - 1] + mi || b[j] + 1 == b[j - 1] + mi)
        k++;
      else {
        ji++;
        break;
      }
      b[j] = b[j - 1] + mi;
    }
    if (!ji) ans = min(k, ans);
  }
  if (ans == 0x7ffffff)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int t = 1;
  while (t--) solve();
  return 0;
}
