# Applying AIC to determine appropriate ARIMA model

If I somehow know that a variable $$Y$$ is explained by an ARIMA process, and I know the number of times that the observations must be "differenced" to obtain a stationary series, I have read that it is appropriate to use AIC to determine the number of regressor variables in the model.

The formula for AIC is $$AIC=2p + 2ln(L)$$, where $$p$$ is the total number of regressors, and $$L$$ is the maximum of the likelihood function, and the best number of regressors is the one which minimizes the AIC.

My question is, if I determine for example that AIC is lowest when $$p=5$$, how do I know which of these five regressors are lagged $$y$$ variables, and which of the five regressors are lagged error terms?