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): if(i==int(len(w)-1)): ans = i+1 break else: pass else: if(width == l): ans = i+1 break if(width > l): ans = i break print(ans)