L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() res = 0 width = 0 for i in range(len(W)-1): width += W[i] if L > width: res += 1 elif L == width: res += 1 break else: pass print(res)