#include <bits/stdc++.h>
using namespace std;
long long f(long long a, long long b, vector<long long> g) {
  long long ans = 0;
  ans += abs(a) + abs(b);
  g[1] += b;
  g[0] += a;
  long long u = g[1] - g[0];
  for (int i = 2; i < (int)(g.size()); ++i) {
    long long u1 = g[i] - g[i - 1];
    if (u1 == u) continue;
    if (u1 + 1 == u) {
      ans++;
      g[i]++;
      continue;
    }
    if (u1 - 1 == u) {
      ans++;
      g[i]--;
      continue;
    }
    return 1e10;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> g(n);
  long long minn = 1e10;
  for (int i = 0; i < n; ++i) {
    cin >> g[i];
    minn = min(minn, g[i]);
  }
  for (int i = 0; i < n; ++i) {
    g[i] -= minn;
  }
  if (g[0] != 0) reverse(g.begin(), g.end());
  if ((int)(g.size()) <= 2) {
    cout << 0;
    return 0;
  };
  long long ans = 1e10;
  ans = min(ans, f(0, 0, g));
  ans = min(ans, f(1, 0, g));
  ans = min(ans, f(-1, 0, g));
  ans = min(ans, f(-1, 1, g));
  ans = min(ans, f(1, -1, g));
  ans = min(ans, f(-1, -1, g));
  ans = min(ans, f(1, 1, g));
  ans = min(ans, f(0, 1, g));
  ans = min(ans, f(0, -1, g));
  if (ans == 1e10)
    cout << -1;
  else
    cout << ans;
}
