import java.io.*;
import java.util.*;

public class seq_vd_slow_wa {
	
	long INF = (long)(1e+13);

	long solve(int[] a, int n, int h) {
		long ans = INF;
		for (int i = 0; i + h <= n; i++) {
			if (a[i] <= 1) {
				long sum = 0;
				for (int j= 0 ; j< h; j++) {
					sum = sum + j + 1 - a[i+j];
				}
				ans = Math.min(ans, sum);
			}
		}
		return (ans == INF) ? -1 : ans;
	}

	public void solve() throws IOException {
		int n = nextInt(), h = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		out.println(solve(a,n,h));
	}

	public void run() throws IOException {
		br = new BufferedReader(new FileReader("seq.in"));
		out = new PrintWriter("seq.out");
		solve();
		out.close();
		br.close();
	}

	public static void main(String[] args) throws IOException {
		new seq_vd_slow_wa().run();
	}

	BufferedReader br;
	StringTokenizer str;
	PrintWriter out;

	String next() throws IOException {
		while (str == null || !str.hasMoreTokens()) {
			str = new StringTokenizer(br.readLine());
		}
		return str.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

}