def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
    print(m)

if __name__ == "__main__":
    main() def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
    print(m) main 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 m = 0 m 0 for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
     k_ range(k+1) range k+1 k 1 v_c = v v_c v if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
         k_>n k_ n v_ = v_c v_ v_c v_c = [] v_c [] s = k-n s k-n k n v_ = v_c[0:k_] v_ v_c[0:k_] v_c 0:k_ 0 k_ v_c = v_c[k_:] v_c v_c[k_:] v_c k_: k_ s = k-k_ s k-k_ k k_ for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
     i range(s+1) range s+1 s 1 if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
             i>len(v_c) i len(v_c) len v_c v__ =v_+ v_c v__ v_+ v_c v_ v_c s_ = s-len(v_c) s_ s-len(v_c) s len(v_c) len v_c v__ = v_+ v_c[len(v_c)-i:] v__ v_+ v_c[len(v_c)-i:] v_ v_c[len(v_c)-i:] v_c len(v_c)-i: len(v_c)-i len(v_c) len v_c i s_ = s-i s_ s-i s i while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
             s_>0 and len(v__)>0 and min(v__)<0 s_>0 and len(v__)>0 s_>0 s_ 0 len(v__)>0 len(v__) len v__ 0 min(v__)<0 min(v__) min v__ 0 v__.pop(v__.index(min(v__))) v__.pop v__ pop v__.index(min(v__)) v__.index v__ index min(v__) min v__ s_ = s_-1 s_ s_-1 s_ 1 if sum(v__)>m:
                m = sum(v__)
     sum(v__)>m sum(v__) sum v__ m m = sum(v__) m sum(v__) sum v__ print(m) print m if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
    print(m) def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
    print(m) main
def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for k_ in range(k+1):
        v_c = v
        if k_>n:
            v_ = v_c
            v_c = []
            s = k-n
        else:
            v_ = v_c[0:k_]
            v_c = v_c[k_:]
            s = k-k_
        for i in range(s+1):
            if i>len(v_c):
                v__ =v_+ v_c
                s_ = s-len(v_c)
            else:
                v__ = v_+ v_c[len(v_c)-i:]
                s_ = s-i
            while s_>0 and len(v__)>0 and min(v__)<0:
                v__.pop(v__.index(min(v__)))
                s_ = s_-1
            if sum(v__)>m:
                m = sum(v__)
    print(m)

if __name__ == "__main__":
    main()