import sys import os f = open("C:/Users/user/Documents/python/yukicoder/import.txt","r") sys.stdin = f # -*- coding: utf-8 -*- l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() for i in range(1,n+1): if l >= w[i]: l -= w[i] else: ans = i break print(ans)