# Confusing stepwise regression process

According to the algorithm for the backward stepwise selection from the book ISLR which is shown below:

says that we need to choose the model among the $$k$$ models by having a smallest RSS or highest $$R^{2}$$, while other resources tells that for choosing the predictor/s to be included in the model based on their $$p$$-values as stated here.

Can someone tell what is the right process?