l = int(input()) n = int(input()) w = list(map(int, input().split(" "))) w.sort() ans = sum = 0 for val in w: if sum + val <= l: sum += val ans += 1 else: break print(ans)