#include <bits/stdc++.h>
using namespace std;
int n, fi, la, cnt;
int b[100005];
int change[3] = {-1, 0, 1};
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  int ans = 100005;
  if (n == 1 || n == 2)
    ans = 0;
  else {
    for (int i = 0; i < 3; i++) {
      fi = b[1] + change[i];
      for (int j = 0; j < 3; j++) {
        la = b[n] + change[j];
        if ((la - fi) % (n - 1) == 0) {
          int d = (la - fi) / (n - 1), flag = 0;
          cnt = 0;
          for (int k = 2; k < n; k++) {
            if (fi + (k - 1) * d == b[k])
              continue;
            else if (abs(b[k] - (fi + (k - 1) * d)) == 1)
              cnt++;
            else {
              flag = 1;
              break;
            }
          }
          if (flag == 0) ans = min(ans, cnt + abs(change[i]) + abs(change[j]));
        }
      }
    }
  }
  if (ans == 100005) ans = -1;
  cout << ans << endl;
  return 0;
}
