def main(L, numbers): sum = 0 for i, num in enumerate(sorted(numbers)): sum += num if sum > L: return i return i + 1 L = int(input()) N = int(input()) numbers = map(int, input().split()) print(main(L, numbers))