L = int(input()) N = int(input()) W = list(map(int, input().split())) cnt = 0 W.sort() while len(W) != 0: if L < W[0]: break else: cnt += 1 L -= W[0] del W[0] print(cnt)