#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int che1(int dif) {
  vector<int> b = a;
  b[1] = b[1]--;
  int ans = 1;
  int n = a.size();
  for (int i = 1; i <= n; i++) {
    if (abs(b[i] - b[i - 1] + dif) <= 1) {
      ans += abs(b[i] - b[i - 1] + dif);
      b[i] = b[i - 1] + dif;
    } else {
      return -1;
    }
  }
}
int che2(int dif) {
  vector<int> b = a;
  int ans = 0;
  int n = a.size();
  for (int i = 1; i <= n; i++) {
    if (abs(b[i] - b[i - 1] + dif) <= 1) {
      ans += abs(b[i] - b[i - 1] + dif);
      b[i] = b[i - 1] + dif;
    } else {
      return -1;
    }
  }
}
int che3(int dif) {
  vector<int> b = a;
  b[1]++;
  int ans = 1;
  int n = a.size();
  for (int i = 1; i <= n; i++) {
    if (abs(b[i] - b[i - 1] + dif) <= 1) {
      ans += abs(b[i] - b[i - 1] + dif);
      b[i] = b[i - 1] + dif;
    } else {
      return -1;
    }
  }
}
int che(int dif) {
  int ans = 1000000;
  if (che1(dif) != -1) ans = min(ans, che1(dif));
  if (che2(dif) != -1) ans = min(ans, che2(dif));
  if (che3(dif) != -1) ans = min(ans, che3(dif));
  if (ans != 1000000) return ans;
  return -1;
}
int check(int i, int j) {
  vector<int> b = a;
  b[1] += i;
  b[2] += j;
  int dif = b[2] - b[1];
  int ans = abs(i) + abs(j);
  int n = a.size() - 1;
  for (int i = 3; i <= n; i++) {
    if (b[i] - b[i - 1] != dif) {
      if (abs(b[i] - b[i - 1] - dif) <= 1) {
        ans += 1;
        b[i] = b[i - 1] + dif;
      } else {
        return -1;
      }
    }
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  a.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << "0";
    return 0;
  }
  int dif = a[2] - a[1];
  int ans = 1000000;
  if (check(0, 0) != -1) ans = min(ans, check(0, 0));
  if (check(0, 1) != -1) ans = min(ans, check(0, 1));
  if (check(1, 0) != -1) ans = min(ans, check(1, 0));
  if (check(-1, 0) != -1) ans = min(ans, check(-1, 0));
  if (check(0, -1) != -1) ans = min(ans, check(0, -1));
  if (check(1, 1) != -1) ans = min(ans, check(1, 1));
  if (check(-1, -1) != -1) ans = min(ans, check(-1, -1));
  if (check(-1, 1) != -1) ans = min(ans, check(-1, 1));
  if (check(1, -1) != -1) ans = min(ans, check(1, -1));
  if (ans == 1000000) {
    cout << "-1";
  } else {
    cout << ans;
  }
}
