import heapq l=int(input()) n=int(input()) w=list(map(int,input().split())) heapq.heapify(w) sum=count=0 while sum <= l: sum += heapq.heappop(w) count += 1 count -= 1 print('%d' % count)