import copy

n, k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(0,n+1):
    for r in range(0,n+1):
        if l+r > n or l+r > k or l+r==0:
            continue
        vc = copy.deepcopy(v)
        have = []
        ll = copy.deepcopy(l)
        rr = copy.deepcopy(r)
        while ll:
            tmp = vc.pop(0)
            have.append(tmp)
            ll -= 1
        while rr:
            tmp = vc.pop(-1)
            have.append(tmp)
            rr -= 1
        have.sort()
        kk = copy.deepcopy(k)
        while have[0] < 0 and kk-(l+r) > 0:
            tmp = have.pop(0)
            kk -= 1
            if not have:
                break
        ans = max(ans, sum(have))
print(ans) import copy copy 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 l in range(0,n+1):
    for r in range(0,n+1):
        if l+r > n or l+r > k or l+r==0:
            continue
        vc = copy.deepcopy(v)
        have = []
        ll = copy.deepcopy(l)
        rr = copy.deepcopy(r)
        while ll:
            tmp = vc.pop(0)
            have.append(tmp)
            ll -= 1
        while rr:
            tmp = vc.pop(-1)
            have.append(tmp)
            rr -= 1
        have.sort()
        kk = copy.deepcopy(k)
        while have[0] < 0 and kk-(l+r) > 0:
            tmp = have.pop(0)
            kk -= 1
            if not have:
                break
        ans = max(ans, sum(have)) l range(0,n+1) range 0 n+1 n 1 for r in range(0,n+1):
        if l+r > n or l+r > k or l+r==0:
            continue
        vc = copy.deepcopy(v)
        have = []
        ll = copy.deepcopy(l)
        rr = copy.deepcopy(r)
        while ll:
            tmp = vc.pop(0)
            have.append(tmp)
            ll -= 1
        while rr:
            tmp = vc.pop(-1)
            have.append(tmp)
            rr -= 1
        have.sort()
        kk = copy.deepcopy(k)
        while have[0] < 0 and kk-(l+r) > 0:
            tmp = have.pop(0)
            kk -= 1
            if not have:
                break
        ans = max(ans, sum(have)) r range(0,n+1) range 0 n+1 n 1 if l+r > n or l+r > k or l+r==0:
            continue
         l+r > n or l+r > k or l+r==0 l+r > n or l+r > k l+r > n l+r l r n l+r > k l+r l r k l+r==0 l+r l r 0 continue vc = copy.deepcopy(v) vc copy.deepcopy(v) copy.deepcopy copy deepcopy v have = [] have [] ll = copy.deepcopy(l) ll copy.deepcopy(l) copy.deepcopy copy deepcopy l rr = copy.deepcopy(r) rr copy.deepcopy(r) copy.deepcopy copy deepcopy r while ll:
            tmp = vc.pop(0)
            have.append(tmp)
            ll -= 1
         ll tmp = vc.pop(0) tmp vc.pop(0) vc.pop vc pop 0 have.append(tmp) have.append have append tmp ll -= 1 ll 1 while rr:
            tmp = vc.pop(-1)
            have.append(tmp)
            rr -= 1
         rr tmp = vc.pop(-1) tmp vc.pop(-1) vc.pop vc pop -1 have.append(tmp) have.append have append tmp rr -= 1 rr 1 have.sort() have.sort have sort kk = copy.deepcopy(k) kk copy.deepcopy(k) copy.deepcopy copy deepcopy k while have[0] < 0 and kk-(l+r) > 0:
            tmp = have.pop(0)
            kk -= 1
            if not have:
                break
         have[0] < 0 and kk-(l+r) > 0 have[0] < 0 have[0] have 0 0 kk-(l+r) > 0 kk-(l+r) kk l+r l r 0 tmp = have.pop(0) tmp have.pop(0) have.pop have pop 0 kk -= 1 kk 1 if not have:
                break
         not have have break ans = max(ans, sum(have)) ans max(ans, sum(have)) max ans sum(have) sum have print(ans) print ans ans = 0 0 ans have = [] [] have vc = copy.deepcopy(v) copy.deepcopy(v) vc tmp = have.pop(0) have.pop(0) tmp ans = max(ans, sum(have)) max(ans, sum(have)) ans ll = copy.deepcopy(l) copy.deepcopy(l) ll tmp = vc.pop(0) vc.pop(0) tmp kk = copy.deepcopy(k) copy.deepcopy(k) kk n, k = map(int,input().split()) map(int,input().split()) n tmp = vc.pop(-1) vc.pop(-1) tmp rr -= 1 1 rr ll -= 1 1 ll rr = copy.deepcopy(r) copy.deepcopy(r) rr k = map(int,input().split()) map(int,input().split()) k v = list(map(int,input().split())) list(map(int,input().split())) v kk -= 1 1 kk
import copy

n, k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(0,n+1):
    for r in range(0,n+1):
        if l+r > n or l+r > k or l+r==0:
            continue
        vc = copy.deepcopy(v)
        have = []
        ll = copy.deepcopy(l)
        rr = copy.deepcopy(r)
        while ll:
            tmp = vc.pop(0)
            have.append(tmp)
            ll -= 1
        while rr:
            tmp = vc.pop(-1)
            have.append(tmp)
            rr -= 1
        have.sort()
        kk = copy.deepcopy(k)
        while have[0] < 0 and kk-(l+r) > 0:
            tmp = have.pop(0)
            kk -= 1
            if not have:
                break
        ans = max(ans, sum(have))
print(ans)