L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() goukei = 0 i = 0 while goukei <= L: try: if goukei + W[i] <= L: goukei += W[i] i += 1 else: break except: break print(i)