You have a stack of N cards numbered from 1 to N in random order.

You want to sort the cards in ascending order using the following procedure:

1. Your initial stack is stack 1.
2. You distribute the cards from stack 1 to stack 2 and 3: you take the topmost card on stack 1, put it on top of stack 2 or stack 3, and repeat until stack 1 is empty.
3. Then you continue with stack 2: you distribute all cards from stack 2 to the existing stack 3 and a new stack 4, according to the same procedure.
4. Continue with the next stacks: stack $k$ is distributed to stack $k+1$ and stack $k+2$.
5. To end the process, some stack $M-1$ is transferred to the stack $M$, one card at a time.

As you can see, only 3 stacks exist at any time. Therefore the 3 stacks in the title.

The question is: if you use a total of M stacks (initial and final stack included), how many cards can you sort regardless of the initial order?

---

Additional notes: 

You choose on which stack to distribute a card. The numbers are visible. You have to figure out the method that maximizes the number N of cards you can sort. 

A valid answer should explain why, not just provide the correct maximum.

You start with 1 single stack of N cards in random order.

You must end with all cards sorted, card 1 at the bottom and card N at the top. (It doesn't really matter, but end it the same way regardless of the starting position).

I have a method but I haven't proven it maximal. I'll accept any result at least as good as mine (but I don't tell what it is).

An algorithm isn't requested, only the value of N. But you should provide a convincing proof that your best N is indeed achievable. This almost implies the algorithm is made explicit.

---

There is a solution in O(log(N)) stacks.

With 5 stacks you can sort 5 cards.