import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value)

if __name__ == '__main__':
    main() import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value) main N, K = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split K V = list(map(int, readline().split())) V list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split max_value = 0 max_value 0 for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
     L range(N+1) range N+1 N 1 for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
     R range(N+1) range N+1 N 1 if L+R>K:
                break
             L+R>K L+R L R K break if L+R>N:
                break
             L+R>N L+R L R N break get = V[:L] get V[:L] V :L L if R>0:
                get += V[-R:]
             R>0 R 0 get += V[-R:] get V[-R:] V -R: -R R get.sort() get.sort get sort rest = K - (L+R) rest K - (L+R) K L+R L R 1 if x<0 else 0 for x in get for x in get x get for x in get 1 if x<0 else 0 x<0 x 0 1 0 minus = sum((1 if x<0 else 0 for x in get)) minus sum((1 if x<0 else 0 for x in get)) sum (1 if x<0 else 0 for x in get) if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
             minus>rest minus rest value = sum(get[rest:]) value sum(get[rest:]) sum get[rest:] get rest: rest x for x in get if x>0 for x in get if x>0 x get x>0 x 0 if x>0 x value = sum((x for x in get if x>0)) value sum((x for x in get if x>0)) sum (x for x in get if x>0) if value>max_value:
                max_value=value
     value>max_value value max_value max_value=value max_value value print(max_value) print max_value if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main read = sys.stdin.buffer.read sys.stdin.buffer.read read def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value) def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value) main readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD INF = float('inf') float('inf') INF
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value)

if __name__ == '__main__':
    main()