L = int(input()) N = int(input()) A = input() a = A.split() for i in range(0,N): a[i] = int(a[i]) s = 0 t = 0 while s < L: m = min(a) if s + m <= L: s = s + m del a[a.index(m)] t += 1 else: break print(t)