# /usr/bin/env python # -*- coding: utf-8 -*- l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() a = [] for i in range(0,n): a.append(w[i]) if sum(a) > l: a.pop(-1) break print(len(a))