def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
    print(m)

        

if __name__ == "__main__":
    main() def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
    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 i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
     i range(k+1) range k+1 k 1 if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
         i > n i n rem = k-n rem k-n k n have = v have v while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
             len(have)>0 and have[0]<0 and rem>0 len(have)>0 and have[0]<0 len(have)>0 len(have) len have 0 have[0]<0 have[0] have 0 0 rem>0 rem 0 have.pop(0) have.pop have pop 0 rem -= 1 rem 1 s = sum(have) s sum(have) sum have if m<s:
                m = s
             m<s m s m = s m s break for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
     j range(i+1) range i+1 i 1 l=j l j r=i-l r i-l i l have = v[0:l]+v[n-r:n] have v[0:l]+v[n-r:n] v[0:l] v 0:l 0 l v[n-r:n] v n-r:n n-r n r n rem = k-i rem k-i k i have = sorted(have) have sorted(have) sorted have if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
             len(have)==0 len(have) len have 0 s = 0 s 0 while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                 len(have)>0 and have[0]<0 and rem>0 len(have)>0 and have[0]<0 len(have)>0 len(have) len have 0 have[0]<0 have[0] have 0 0 rem>0 rem 0 have.pop(0) have.pop have pop 0 rem -= 1 rem 1 s = sum(have) s sum(have) sum have if m<s:
                m = s
     m<s m s m = s m s 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 i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
    print(m)

         def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
    print(m)

         main
def main():
    n,k = map(int,input().split())
    v = list(map(int,input().split()))
    m = 0
    for i in range(k+1):
        if i > n:
            rem = k-n
            have = v
            while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
            s = sum(have)
            if m<s:
                m = s
            break
        for j in range(i+1):
            l=j
            r=i-l
            have = v[0:l]+v[n-r:n]
            rem = k-i
            have = sorted(have)
            if len(have)==0:
                s = 0
            else:
                while len(have)>0 and have[0]<0 and rem>0:
                    have.pop(0)
                    rem -= 1
                s = sum(have)
            if m<s:
                m = s
    print(m)

        

if __name__ == "__main__":
    main()