L = int(input()) N = int(input()) W = list(map(int,input().split())) count = [0] * 10001 for i in W: count[i] += 1 c = 0 for i in range(1,10001): if count[i] != 0: if L < i: break else: q = min(L // i,count[i]) c += q L = L - i * q print(c)