N,K = list(map(int,input().split()))

V = list(map(int,input().split()))



ans = 0

for l in range(N):

  for r in range(N-l+1):

    arr = V[:l] + ([] if r==0 else V[-r:])

    k = len(arr)

    if k > K: continue

    score = sum(arr)

    arr.sort()

    i = 0

    while k < K and i < len(arr):

      if arr[i] >= 0: break

      score -= arr[i]

      k += 1

      i += 1

    ans = max(ans, score)

print(ans)
N,K = list(map(int,input().split()))

V = list(map(int,input().split()))



ans = 0

for l in range(N):

    if l > K: break

    for r in range(N-l+1):

        if l+r > K: break

        vs = V[:l] + (V[-r:] if r>0 else [])

        vs.sort()

        k = K-l-r

        t = 0

        for v in vs:

            if v < 0 and k > 0:

                k -= 1

                continue

            t += v

        ans = max(ans,t)

print(ans)
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for l in range(N):
    for r in range(N - l + 1):
        arr = V[:l] + ([] if r == 0 else V[-r:])
        k = len(arr)
        if k > K:
            continue
        score = sum(arr)
        arr.sort()
        i = 0
        while k < K and i < len(arr):
            if arr[i] >= 0:
                break
            score -= arr[i]
            k += 1
            i += 1
        ans = max(ans, score)
print(ans)

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for l in range(N):
    if l > K:
        break
    for r in range(N - l + 1):
        if l + r > K:
            break
        vs = V[:l] + (V[-r:] if r > 0 else [])
        vs.sort()
        k = K - l - r
        t = 0
        for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
        ans = max(ans, t)
print(ans)

+    if l > K: +        break -        arr = V[:l] + ([] if r == 0 else V[-r:]) -        k = len(arr) -        if k > K: -            continue -        score = sum(arr) -        arr.sort() -        i = 0 -        while k < K and i < len(arr): -            if arr[i] >= 0: -                break -            score -= arr[i] -            k += 1 -            i += 1 -        ans = max(ans, score) +        if l + r > K: +            break +        vs = V[:l] + (V[-r:] if r > 0 else []) +        vs.sort() +        k = K - l - r +        t = 0 +        for v in vs: +            if v < 0 and k > 0: +                k -= 1 +                continue +            t += v +        ans = max(ans, t)