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