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

# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:]))
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 for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:])) l range(0, k + 1) range 0 k + 1 k 1 for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:])) r range(0, k + 1 - l) range 0 k + 1 - l k + 1 k 1 l if l + r > n:
            continue
         l + r > n l + r l r n continue suteru = k - l - r suteru k - l - r k - l k l r get = [] get [] for i in range(l):
            get.append(v[i])
         i range(l) range l get.append(v[i]) get.append get append v[i] v i for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
         i range(n - 1, n - 1 - r, -1) range n - 1 n 1 n - 1 - r n - 1 n 1 r -1 get.append(v[i]) get.append get append v[i] v i get.sort() get.sort get sort minus = 0 minus 0 while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
         minus < min(suteru, len(get)) and get[minus] < 0 minus < min(suteru, len(get)) minus min(suteru, len(get)) min suteru len(get) len get get[minus] < 0 get[minus] get minus 0 minus += 1 minus 1 ans = max(ans, sum(get[minus:])) ans max(ans, sum(get[minus:])) max ans sum(get[minus:]) sum get[minus:] get minus: minus print(ans) print ans v = list(map(int, input().split())) list(map(int, input().split())) v n, k = map(int, input().split()) map(int, input().split()) n get = [] [] get suteru = k - l - r k - l - r suteru k = map(int, input().split()) map(int, input().split()) k ans = 0 0 ans minus = 0 0 minus minus += 1 1 minus ans = max(ans, sum(get[minus:])) max(ans, sum(get[minus:])) ans
n, k = map(int, input().split())
v = list(map(int, input().split()))

# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:]))
print(ans)
