import java.util.*;
public class P5 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt(), k = cin.nextInt();
int[] nums = new int[n + 1];
for (int i = 1; i <= n; i++) {
nums[i] = cin.nextInt();
}
int[][] dp = new int[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (i == 1) {
dp[i][j] = nums[i];
} else if (j == 0) {
dp[i][j] = Math.max(dp[i - 1][j], nums[i] + dp[i - 2][j]);
} else {
dp[i][j] = Math.max(dp[i - 1][j], nums[i] + Math.max(dp[i - 1][j - 1], dp[i - 2][j]));
}
}
}
System.out.println(dp[n][k]);
}
}
#我的实习求职记录#