class Problem0005: def solve(this): l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() res = 0 cnt = 0 for i in range(0, len(w)): res += w[i] if res > l: break cnt += 1 print(cnt) if __name__ == "__main__": problem = Problem0005() problem.solve()