# -*- coding: utf-8 -*- L = input() N = input() W = map(int, raw_input().split()) W.sort() tot = 0 cnt = 0 while tot < L and cnt < N: tot += W[cnt] cnt += 1 if L < tot: cnt -= 1 print cnt