L,N = input(),input() W = map(int,raw_input().split()) W.sort() nowWidth = 0 count = 0 for width in W: nowWidth += width if nowWidth > L: print count break count += 1