Captain Gains and Losses

In 2022 I had capital losses of $16K and only used $3K leave a carryover of $13K short term

and 

In 2023 I had a capital gain of $31K short tem - can I take all of $13K carryover from 2022 or I can only take $3K?