
N, K, *p = map(int, open(0).read().split())

import itertools
lis = list(itertools.combinations(range(N), 3))

if len(lis) == 0:
    print(p[0])
    import sys
    sys.exit()

mi = -1
for x in lis:
    cur = 0
    for pos in x:
        cur += p[pos]

    print(cur)

    if mi == -1:
        mi = cur
    else:
        mi = min(mi, cur)

print(mi)
#print(lis)
