s = input().split()
intN = int(s[0])
intK = int(s[1])

inList = list(map(int,input().split()))

#print(inList)
inList.sort()

#print(inList)

idx = 0
intCnt = 0

for wInt in inList:
    if (idx < 3) :
        intCnt += wInt
        #print(wInt) 
        #print(intCnt) 
    idx += 1

print(intCnt) 