n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
min_nk = min(n, k)
for l in range(min_nk+1):
    for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        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 min_nk = min(n, k) min_nk min(n, k) min n k for l in range(min_nk+1):
    for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        ans = max(ans, sum(hand)) l range(min_nk+1) range min_nk+1 min_nk 1 for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        ans = max(ans, sum(hand)) r range(min_nk-l+1) range min_nk-l+1 min_nk-l min_nk l 1 hand = [] hand [] for i in range(l):
            hand.append(v[i])
         i range(l) range l hand.append(v[i]) hand.append hand append v[i] v i for i in range(r):
            hand.append(v[n-1-i])
         i range(r) range r hand.append(v[n-1-i]) hand.append hand append v[n-1-i] v n-1-i n-1 n 1 i hand.sort() hand.sort hand sort for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
         i range(min(k-l-r, len(hand))) range min(k-l-r, len(hand)) min k-l-r k-l k l r len(hand) len hand if hand[i] < 0:
                hand[i] = 0
         hand[i] < 0 hand[i] hand i 0 hand[i] = 0 hand[i] hand i 0 ans = max(ans, sum(hand)) ans max(ans, sum(hand)) max ans sum(hand) sum hand print(ans) print ans k = map(int, input().split()) map(int, input().split()) k v = list(map(int, input().split())) list(map(int, input().split())) v ans = 0 0 ans n, k = map(int, input().split()) map(int, input().split()) n ans = max(ans, sum(hand)) max(ans, sum(hand)) ans hand = [] [] hand min_nk = min(n, k) min(n, k) min_nk
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
min_nk = min(n, k)
for l in range(min_nk+1):
    for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        ans = max(ans, sum(hand))
print(ans)