Measurement of electrons from beauty-hadron decays in p-Pb collisions at sNN=5.02 TeV and Pb-Pb collisions at sNN=2.76 TeV