l = int(input()) n = int(input()) w = input().split() for i in range(len(w)): w[i] = int(w[i]) for i in range(len(w)): i = int(i) minimum = w[i] m = i for j in range(i+1,len(w)): if(minimum > w[j]): minimum = w[j] m = j w[m] = w[i] w[i] = minimum width = 0 for i in range(len(w)): i = int(i) width += w[i] if(width < l and i==int(len(w))-1): ans = i+1 break elif(width == 1): ans = i+1 break elif(width > l): ans = i break elif(width < 1): pass print(ans)