Rapidity dependence of particle densities in pp and AA collisions