def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans
print(solve()) def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans solve 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 V *= 2 V 2 ans = 0 ans 0 for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
     i range(N+1) range N+1 N 1 for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
     j range(N-1,2*N) range N-1 N 1 2*N 2 N num = j-i+1 num j-i+1 j-i j i 1 if num>K or num>N or num == 0:
                continue
             num>K or num>N or num == 0 num>K or num>N num>K num K num>N num N num == 0 num 0 continue lis = V[i:j+1] lis V[i:j+1] V i:j+1 i j+1 j 1 lis.sort() lis.sort lis sort margin = K-num margin K-num K num m = sum(lis) m sum(lis) sum lis k = 0 k 0 while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
             k < margin and k < num and lis[k]<0 k < margin and k < num k < margin k margin k < num k num lis[k]<0 lis[k] lis k 0 m -= lis[k] m lis[k] lis k k += 1 k 1 ans = max(ans,m) ans max(ans,m) max ans m return ans ans print(solve()) print solve() solve def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans solve
def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans
print(solve())