l = int(input()) sum = 0; count = 0 n = int(input()) m = sorted(input().split()) for i in m: sum += i if sum > l: break count += 1 print(count)