def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans)

if __name__ == '__main__':
    abc128_d() def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans) abc128_d 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(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
     a range(max(1, k+1)) range max(1, k+1) max 1 k+1 k 1 for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
     b range(max(1, k-a+1)) range max(1, k-a+1) max 1 k-a+1 k-a k a 1 if a+b > n: break
             a+b > n a+b a b n arr = [] arr [] if a > 0: arr += v[:a]
             a > 0 a 0 if b > 0 and a < n: arr += v[max(a, 0, n-b):]
             b > 0 and a < n b > 0 b 0 a < n a n arr.sort() arr.sort arr sort for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
     j range(max(1, a+b)) range max(1, a+b) max 1 a+b a b if a+b+j > k: break
                 a+b+j > k a+b+j a+b a b j k score = sum(arr[j:]) score sum(arr[j:]) sum arr[j:] arr j: j ans = max(ans, score) ans max(ans, score) max ans score print(ans) print ans if __name__ == '__main__':
    abc128_d() __name__ == '__main__' __name__ '__main__' abc128_d() abc128_d def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans) def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans) abc128_d
def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  # 左から取る個数
        for b in range(max(1, k-a+1)):  # 右から取る個数
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  # 戻す個数
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans)

if __name__ == '__main__':
    abc128_d()