L = int(input()) N = int(input()) ln_W = sorted(list(map(int, input().split()))) i = 0 while i <= N-1: L -= ln_W[i] if L < 0: break else: i += 1 print(i)