# -*- coding: utf-8 -*- hako = int(input()) kosuu = int(input()) width = input().split() width_i = [int(s) for s in width] width_i.sort() count = 0 total = 0 for i in width_i: total = total + i count += 1 if total > hako: count = count - 1 break print(count)