First measurement of jet mass in Pb–Pb and p–Pb collisions at the LHC