#fileencoding: utf-8 from __future__ import print_function def main(): L = int(raw_input()) N = int(raw_input()) W = sorted([int(i) for i in raw_input().split()]) count = 0 for i in W: L -= i if L >= 0: count += 1 print(count) if __name__ == "__main__": main()