N, K = map(int,input().split())
v = list(map(int,input().split()))
ans = [0]
for i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
        get.sort()
        for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
        ans.append(A)
print(max(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] 0 for i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
        get.sort()
        for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
        ans.append(A) i range(1,min(K,N)+1) range 1 min(K,N)+1 min(K,N) min K N 1 for a in range(i+1):
        b = i-a
        if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
        get.sort()
        for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
        ans.append(A) a range(i+1) range i+1 i 1 b = i-a b i-a i a if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
         b == 0 b 0 get = v[:a] get v[:a] v :a a get = v[:a]+v[-b:] get v[:a]+v[-b:] v[:a] v :a a v[-b:] v -b: -b b get.sort() get.sort get sort for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
         j range(min(K-i,len(get))) range min(K-i,len(get)) min K-i K i len(get) len get p = get.pop(0) p get.pop(0) get.pop get pop 0 if p >= 0:
                A = p + sum(get)
                break
         p >= 0 p 0 A = p + sum(get) A p + sum(get) p sum(get) sum get break A = sum(get+[0]) A sum(get+[0]) sum get+[0] get [0] 0 ans.append(A) ans.append ans append A print(max(ans)) print max(ans) max ans ans = [0] [0] ans p = get.pop(0) get.pop(0) p v = list(map(int,input().split())) list(map(int,input().split())) v A = p + sum(get) p + sum(get) A b = i-a i-a b N, K = map(int,input().split()) map(int,input().split()) N get = v[:a]+v[-b:] v[:a]+v[-b:] get get = v[:a] v[:a] get A = sum(get+[0]) sum(get+[0]) A 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 i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
        get.sort()
        for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
        ans.append(A)
print(max(ans))