import itertools

N, K = map(int, input().split())
A = input().split()
L = [int(b.strip()) for b in A]  

#print(N)
#print(K)
#print(L)

ret = 1000
for v in itertools.combinations(L, 3):
    #print(v)
    s = sum(v)
    #print(s)
    if ret > s:
      ret = s

print(ret)