l = int(input()) n = int(input()) w = list(map(int,input().split())) w1 = sorted(w) ans = 0 count = 0 for i in w1: ans += i if(ans < l): count += 1 print(count)