# coding: utf-8 L = int(input()) N = int(input()) length = sorted([int(i) for i in input().split()]) s = 0 for i in range(N): L = L-length[i] if L < 0: break else: s = s + 1 print(s)