A positive integer $N$ has 20 digits when written in base 9 and 13 digits when written in base 27. How many digits does $N$ have when written in base 3?

Let's think step by step and output the final answer within \boxed{}.
user