L = int(raw_input()) N = int(raw_input()) W = tuple(sorted(map(int, raw_input().split()))) while True: tmp = sum(W[0:N-1]) if tmp <= L: print N break else: if N % 2 == 0: N = N / 2 else: N = (N + 1) / 2