import sequtils,strutils,algorithm var L = stdin.readline.parseInt N = stdin.readline.parseInt W = stdin.readline.split.map(parseInt) cnt,ans : int W.sort(system.cmp) cnt = 0 ans = -1 for i,w in W: cnt += w if cnt > L: ans = i break if ans == -1: echo N else: echo ans