#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int main() {
  int n, ans = -1, ar[100005];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 1; i >= -1; i--) {
    int a = ar[0] + i;
    for (int j = 1; j >= -1; j--) {
      int cn = abs(i) + abs(j);
      int b = ar[1] + j;
      int d = b - a;
      int flag = 1;
      for (int k = 2; k < n; k++) {
        int x = b + d;
        if (abs(ar[k] - x) <= 1) {
          cn += abs(ar[k] - x);
          b = x;
        } else {
          flag = 0;
          break;
        }
      }
      if (flag) {
        if (ans == -1)
          ans = cn;
        else
          ans = min(ans, cn);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
