def scan_input():
    L = int(input())
    N = int(input())
    W = input()
    W = W.split()
    W = [int(w) for w in W]
    return (L, N, W)


def cal_ans(L, W):
    W.sort()
    buf = 0
    for i, w in enumerate(W, 0):
        if (buf + w) > L:
            break
        elif (len(W) - 1) == i:
            i += 1
            break
        else:
            buf += w
    return i


if __name__ == "__main__":
    L, N, W = scan_input()
    print(cal_ans(L, W))