n = int(input()) m = int(input()) w = list(sorted(map(int,input().split()))) count = 0 for i in range(m): n -= w[i] if n < 0: print(count) count += 1