r = lambda: map(int, raw_input().split()) n, m = r() w = r() INF = 10**9 dp = [[-INF]*(m+1) for i in xrange(n)] b = w[-1] def dfs(c, s): if s==m: return b if c==n-1 else 0 if c>=n: return -INF v = dp[c][s] if v!=-INF: return v ret = dfs(c+1, s+1) + w[c] for i in xrange(c+2,n): ret = max(ret, dfs(i, s+1)) dp[c][s] = ret return ret a = w[0] + dfs(1, 2) for i in xrange(2, n): a = max(a, dfs(i, 2)) dp = [[-INF]*(m+1) for i in xrange(n)] b = 0 for i in xrange(1, n): a = max(a, dfs(i, 1)) print a