l,n,s= int(input()),int(input()),0 w=sorted(list(map(int,input().split()))) for i in range(n): if (s:=s+w[i])>l: print(i) break else:print(n)