# coding: utf-8 def II(): return int(input()) def ILI(): return list(map(int, input().split())) L = II() N = II() W = ILI() W.sort() block_sum = 0 for i in range(N): block_sum += W[i] if block_sum > L: print(i) break