L = int(input()) N = int(input()) W = list(map(int, input().split(" "))) sorted_W = sorted(W) sum_len = 0 i = 0 for w in sorted_W: if sum_len+w > L: break else: sum_len += w i += 1 print(i)