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