L = int(input()) N = int(input()) lst = sorted(map(int, input().split())) n, w = 0, 0 for i in lst: if w + i > L: break n += 1 print(n)