import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): L = int(input()) N = int(input()) W = [int(x) for x in input().split()] W.sort() total = 0 ans = 0 for w in W: total += w if total > L: break ans += 1 print(ans) if __name__ == '__main__': main()