// Arup Guha
// 5/26/2016
// Solution to 2016 February USACO Gold Problem: Circular Barn 2

import java.util.*;
import java.io.*;

public class cbarn2 {

	public static void main(String[] args) throws Exception {

		// Read in data.
		Scanner stdin = new Scanner(new File("cbarn2.in"));
		int n = stdin.nextInt();
		int open = stdin.nextInt();

		int[] vals = new int[n];
		for (int i=0; i<n; i++)
			vals[i] = stdin.nextInt();

		long res = 100000000000L;

		// Try each starting location for first barn door.
		for (int start=0; start<n; start++) {

            // Shift data accordingly.
			int[] arr = new int[n];
			for (int i=start; i<start+n; i++) arr[i-start] = vals[i%n];

            // Set up DP - init row for one door open.
			long[][] dp = new long[open][n];
			for (int i=1; i<n; i++) dp[0][i] = dp[0][i-1] + i*arr[i];

            // Fill in solution for rest of the states dp[i][j] is for using i+1 doors, covering
            // the first j items.
			for (int i=1; i<open; i++) {
				for (int j=i+1; j<n; j++) {

                    // Just put a door at index j, no cost for these cows.
					dp[i][j] = dp[i-1][j];
					int sum = 0, people = arr[j];
					int k=j-1;

					// Work backwards including more rooms into the last group. k is where
					// the last door is.
					while (k > 0 && sum < dp[i][j]) {
						sum += people;
						dp[i][j] = Math.min(dp[i][j], dp[i-1][k-1]+sum);
						people += arr[k];
						k--;
					}
				}
			}

            // Take the best answer.
			res = Math.min(res, dp[open-1][n-1]);
		}

		// Write result.
		PrintWriter out = new PrintWriter(new FileWriter("cbarn2.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}
