# -*- 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 - 1 break print(ans)