# -*- coding: utf-8 -*- l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() g = [0] * n for i in range(n): g[i] = sum(w[:(i+1)]) answer = 0 for i in range(n): if g[i] > l: answer = i break else: answer = n print(answer)