L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() res = 0 weight = 0 for w in W: if weight + w > L: break res += 1 weight += w print(res)