l = int(input()) n = int(input()) w = list(map(int,input().split())) w_sort = sorted(w) ans = 0 count = 0 for i in w_sort: count += i if count <= l: ans += 1 elif count > l: break print(ans)