#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int arr[N + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (n <= 2)
    cout << 0 << '\n';
  else {
    int ans = 0x3f3f3f3f;
    for (int i = arr[1] - 1; i <= arr[1] + 1; i++) {
      for (int j = arr[2] - 1; j <= arr[2] + 1; j++) {
        int temp = abs(arr[1] - i) + abs(arr[2] - j);
        int r = j - i;
        for (int k = 3; k <= n; k++) {
          if (abs((i + (k - 1) * r) - arr[k]) > 1) {
            temp = 0x3f3f3f3f;
            break;
          } else if (arr[k] != (i + (k - 1) * r))
            temp++;
        }
        ans = min(ans, temp);
      }
    }
    cout << (ans == 0x3f3f3f3f ? -1 : ans) << '\n';
  }
  return 0;
}
