#include <cstdio>

int main() {
    freopen("seq.in", "r", stdin);
    freopen("seq.out", "w", stdout);

    int n, h;
    scanf("%d%d", &n, &h);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    long long ans = -1;
    for (int i = 0; i <= n - h; i++) {
        long long v = 0;
        bool ok = true;
        for (int j = 0; j < h; j++) {
            if (a[i + j] > j + 1) {
                ok = false;
                break;
            }
            v += j + 1 - a[i + j];
        }
        if (ok && (ans == -1 || v < ans)) {
            ans = v;
        }
    }

    printf("%I64d\n", ans);

    return 0;
}
