import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np L = int(readline()) N = int(readline()) W = np.array(read().split(), np.int64) W.sort() Wcum = np.cumsum(W) answer = (Wcum <= L).sum() print(answer)