High baryon densities in heavy ion collisions at energies attainable at the BNL Relativistic Heavy-Ion Collider and the CERN Large Hadron Collider