def main():
from sys import stdin
n,k=map(int,stdin.readline().split())
s=list(map(int,stdin.readline().split()))
dp=[[0]*(n+2) for _ in range(k+2)]
for i in range(1,k+2):
for j in range(2,n+2):
#if i==2:print(dp[i-1][j-2]+s[j-2],dp[i][j-1]+s[j-2])
#aaa=max(dp[])
dp[i][j]=max(dp[i-1][j-2]+s[j-2],dp[i][j-1]+s[j-2])
#for i in range(k+2):print(*dp[i])
print(max(dp[k+1]))
if __name__=="__main__":main()