l = int(input()) n = int(input()) ans = 0 cnt = 0 w = list(map(int, input().split())) w.sort() for i in w : ans += i if ans < l : cnt +=1 print(cnt)