l = int(input()) n = int(input()) w = [int(x) for x in input().split()] w.sort() now = 0 cnt = 0 while l > now: now += w[cnt] cnt += 1 print(cnt-1)