import sys input = sys.stdin.buffer.readline L = int(input()) N = int(input()) Ws = sorted(list(map(int, input().split()))) s = 0 cnt = 0 while s < L: s += Ws[cnt] cnt += 1 print(cnt - 1)