L = int(input())
N = int(input())
W = list(map(int, input().split()))

#大きい順(降順)にソート
W.sort()

#カウンタ変数
count = 0

for width in W:
    L -= width
    if L < 0:
        break
    count += 1

print(count)