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

public class seq_vd_wa1 {

	long solve(int[] a, int n, int h) {
		long max = -1;
		int firstPossiblePostion = n - 1;
		long sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum = sum + a[i];
			if (i + h < n) {
				sum = sum - a[i + h];
			}
			if (i+h <= n && i <= firstPossiblePostion && a[i] <= 1) {
				max = Math.max(max, sum);
			}
			firstPossiblePostion = Math.min(firstPossiblePostion, i - a[i]+1);
		}
		return (max == -1) ? max : (long) h * (long) (h + 1) / 2L - max;
	}

	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_wa1().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());
	}

}