# -*- coding: utf-8 -*- L = input() N = input() W = map(int, raw_input().split()) C = 0 W.sort() for i in xrange(len(W)): if L - W[i] > 0: L = L - W[i] C += 1 print C