N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for A in range(min(N, K)+1):
    for B in range(min(N, K)+1-A):
        hand = V[:A]+V[N-B:]
        hand.sort()
        i = 0
        while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
        ans = max(ans, sum(hand))
print (ans) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V = list(map(int, input().split())) V list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for A in range(min(N, K)+1):
    for B in range(min(N, K)+1-A):
        hand = V[:A]+V[N-B:]
        hand.sort()
        i = 0
        while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
        ans = max(ans, sum(hand)) A range(min(N, K)+1) range min(N, K)+1 min(N, K) min N K 1 for B in range(min(N, K)+1-A):
        hand = V[:A]+V[N-B:]
        hand.sort()
        i = 0
        while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
        ans = max(ans, sum(hand)) B range(min(N, K)+1-A) range min(N, K)+1-A min(N, K)+1 min(N, K) min N K 1 A hand = V[:A]+V[N-B:] hand V[:A]+V[N-B:] V[:A] V :A A V[N-B:] V N-B: N-B N B hand.sort() hand.sort hand sort i = 0 i 0 while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
         i < K-A-B and i < len(hand) and hand[i] < 0 i < K-A-B and i < len(hand) i < K-A-B i K-A-B K-A K A B i < len(hand) i len(hand) len hand hand[i] < 0 hand[i] hand i 0 hand[i] = 0 hand[i] hand i 0 i += 1 i 1 ans = max(ans, sum(hand)) ans max(ans, sum(hand)) max ans sum(hand) sum hand print (ans) print ans i += 1 1 i ans = 0 0 ans i = 0 0 i V = list(map(int, input().split())) list(map(int, input().split())) V ans = max(ans, sum(hand)) max(ans, sum(hand)) ans N, K = map(int, input().split()) map(int, input().split()) N hand = V[:A]+V[N-B:] V[:A]+V[N-B:] hand K = map(int, input().split()) map(int, input().split()) K
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for A in range(min(N, K)+1):
    for B in range(min(N, K)+1-A):
        hand = V[:A]+V[N-B:]
        hand.sort()
        i = 0
        while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
        ans = max(ans, sum(hand))
print (ans)