# coding: utf-8 #d, p = map(int,input().split()) l = int(input()) N = int(input()) W = list(map(int,input().split())) W.sort() ans = 0 for i in range(N): l -= W[i] if l >= 0: ans += 1 else: break print(ans)