L = int(input()) N = int(input()) W = [int(x) for x in input().split()] W.sort() num = 0 BL = 0 while (BL < L) and (num < N): BL += W[num] num += 1 if BL >= L: num -= 1 print(num)