#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long n, a[N], b[N], tmp, ans, sl, mmin;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]++;
  b[2]++;
  ans = b[2] - b[1];
  sl = 2;
  mmin = 9999999999999LL;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]++;
  b[2]--;
  ans = b[2] - b[1];
  sl = 2;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]++;
  ans = b[2] - b[1];
  sl = 1;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]--;
  b[2]++;
  ans = b[2] - b[1];
  sl = 2;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]--;
  b[2]--;
  ans = b[2] - b[1];
  sl = 2;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[1]--;
  ans = b[2] - b[1];
  sl = 1;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[2]++;
  ans = b[2] - b[1];
  sl = 1;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  b[2]--;
  ans = b[2] - b[1];
  sl = 1;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  ans = b[2] - b[1];
  sl = 0;
  for (int i = 2; i <= n - 1; i++) {
    if (b[i + 1] - b[i] != ans) {
      tmp = b[i + 1] + 1;
      if (tmp - b[i] == ans) {
        b[i + 1] = tmp;
        sl++;
        continue;
      } else {
        tmp = b[i + 1] - 1;
        if (tmp - b[i] == ans) {
          b[i + 1] = tmp;
          sl++;
          continue;
        } else {
          sl = 9999999999999LL;
          break;
        }
      }
    }
  }
  mmin = min(mmin, sl);
  if (mmin == 9999999999999LL)
    cout << -1;
  else
    cout << mmin;
  return 0;
}
