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 if (cnt == n) and (l >= now): cnt += 1 break print(cnt - 1)