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