import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main()
print(main()) import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy math itertools fractions heapq collections bisect sys queue copy sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf=10**20 inf 10**20 10 20 mod=10**9+7 mod 10**9+7 10**9 10 9 7 dd=[(-1,0),(0,1),(1,0),(0,-1)] dd [(-1,0),(0,1),(1,0),(0,-1)] (-1,0) -1 0 (0,1) 0 1 (1,0) 1 0 (0,-1) 0 -1 ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] (-1,0) -1 0 (-1,1) -1 1 (0,1) 0 1 (1,1) 1 1 (1,0) 1 0 (1,-1) 1 -1 (0,-1) 0 -1 (-1,-1) -1 -1 int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()] LI def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def LS(): return sys.stdin.readline().split() LS def S(): return input() S def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main() main n,k=LI() n LI() LI k v=LI() v LI() LI ans=0 ans 0 for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

   i range(k) range k if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

   i+1<n i+1 i 1 n for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
     l range(i+1) range i+1 i 1 r=i-l r i-l i l _ans=0 _ans 0 _v=[] _v [] for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
         x range(l+1) range l+1 l 1 _ans+=v[x] _ans v[x] v x _v.append(v[x]) _v.append _v append v[x] v x for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

         x range(r) range r _ans+=v[n-x-1] _ans v[n-x-1] v n-x-1 n-x n x 1 _v.append(v[n-x-1]) _v.append _v append v[n-x-1] v n-x-1 n-x n x 1 _v.sort() _v.sort _v sort for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
         j range(min(len(_v),k-i-1)) range min(len(_v),k-i-1) min len(_v) len _v k-i-1 k-i k i 1 if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
         _v[j]<0 _v[j] _v j 0 _ans-=_v[j] _ans _v[j] _v j break ans=max(ans,_ans) ans max(ans,_ans) max ans _ans _v=v.sort() _v v.sort() v.sort v sort _ans=sum(v) _ans sum(v) sum v _k=n-k-1 _k n-k-1 n-k n k 1 for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
       j range(_k) range _k if _v[j]<0:
          _ans-=_v[j]
        else:
          break
       _v[j]<0 _v[j] _v j 0 _ans-=_v[j] _ans _v[j] _v j break ans=max(ans,_ans) ans max(ans,_ans) max ans _ans return ans ans print(main()) print main() main def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()] LI dd=[(-1,0),(0,1),(1,0),(0,-1)] [(-1,0),(0,1),(1,0),(0,-1)] dd ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn def S(): return input() def S(): return input() S inf=10**20 10**20 inf mod=10**9+7 10**9+7 mod def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main() def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main() main
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main()
print(main())
