#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int arr[maxn];
int vis[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  if (n == 1 || n == 2) {
    cout << 0 << endl;
    return 0;
  }
  int ans = maxn * 10;
  for (int i = -1; i < 2; ++i) {
    for (int k = -1; k < 2; ++k) {
      memset(vis, 0, sizeof vis);
      vis[0] = i;
      vis[1] = k;
      int val = arr[1] + vis[1] - arr[0] - vis[0];
      int cnt = 0;
      if (i) ++cnt;
      if (k) ++cnt;
      for (int j = 1; j < n - 1; ++j) {
        if (arr[j + 1] - arr[j] - vis[j] == val)
          continue;
        else if (arr[j + 1] - arr[j] - vis[j] == val - 1)
          ++cnt, vis[j + 1] = 1;
        else if (arr[j + 1] - arr[j] - vis[j] == val + 1)
          ++cnt, vis[j + 1] = -1;
        else {
          cnt = maxn * 10;
          break;
        }
      }
      ans = min(ans, cnt);
    }
  }
  if (ans == maxn * 10)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
