Contact the frame manufacturer because they will have a maximum on seatpost length allowed - then just buy that. Anything longer can cause frame damage. Trek's max on my bike was 360mm of post length.
An overly long seatpost makes a great lever to bend your frame.
Many manufacturers make seatposts well in excess of 400mm.