# -*- coding: utf-8 -*- def main(): L = int(input()) N = int(input()) W = [int(w) for w in input().split()] length = 0 count = 0 W = sorted(W) for w in W: if (length + w) <= L: count += 1 length += w else: break print(count) if __name__ == '__main__': main()