L = int(input()) N = int(input()) M = list(input()) a=0 M.sort() for i in range(N): if L >= a: a = a + M[i] print(a)