import bisect import numpy as np l = int(input()) n = int(input()) w = sorted(list(map(int,input().split()))) cumsum = np.cumsum(w) print(bisect.bisect_left(cumsum, l))