import sys def check_range(a,b,x): if a > x or b < x: sys.exit() def check_eq(a,b): if a != b: sys.exit() L = int(input()) check_range(1,10000,L) N = int(input()) check_range(1,10000,N) data = input().split(' ') check_eq(len(data),N) for i in range(0,N): data[i] = int(data[i]) check_range(1,L,N) size = 0 cnt = 0 data.sort() print(data) for i in range(0,N): if data[i] + size <= L: cnt += 1 size += data[i] else: break print(cnt)