l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() current_sum = 0 count = 0 for width in w: if current_sum + width > l: break current_sum += width count += 1 print(count)