import math l = int(input()) n = int(input()) bArr = input().split(' ') bArrInt = [] for i in range(n): bArrInt.append(int(bArr[i])) bArrSor = sorted(bArrInt) buff = l count = 0 for i in range(n): buff = buff - bArrSor[i] if buff >= 0: count = count + 1 else: break print(count)