Whenever you should be able to take a piece and that specific piece is not in the supply, you take another piece of the same level according to your choice. When there are no pieces of the same level available, you take a piece (your choice) that is one level higher.
This applies to upgrading pieces, getting pieces as rewards for completing puzzles, and also for taking new level-1 pieces.