L = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() ans = 0 while L >= w[0]: L = L - w.pop(0) ans = ans + 1 print(ans)