from strutils import split, parseInt from sequtils import map from algorithm import sort var l = readLine(stdin).parseInt() var n = readline(stdin).parseInt() var ws = readLine(stdin).split(' ').map(parseInt) ws.sort(system.cmp[int]) var i = 0 var width = 0 while i < n: width += ws[i] if width > l: break i += 1 echo i