#coding: utf-8 l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() s = 0 count = 0 for i in w: if s > l: break s = s + i count = count + 1 print(count - 1)