l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() ans, tot = 0, 0 for i in range(n): tot += w[i] if l >= tot: ans += 1 else: break print(ans)