L = int(input()) N = int(input()) W = list(map(int,input().split(" "))) size = 0 cnt = 0 while size <= L: size += W.pop(W.index(min(W))) cnt += 1 print(cnt -1)