L,N = input(),input() W = map(int,raw_input().split()) W.sort() nowWidth = 0 ans = [] for width in W: nowWidth += width if nowWidth > L: break ans.append(width) print len(ans)