import numpy as np L = int(input()) n = int(input()) W = list(map(int, input().split())) W.sort() Wcum = np.cumsum(W) ans = (Wcum <= L).sum() print(ans)