def main(): L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() count = 0 for w in W: if w <= L: count += 1 L -= w else: break print(count) if __name__ == "__main__": # {{{ try: import test test.test() except: main() # }}}