Probing the chiral magnetic wave in pPb and PbPb collisions at sNN =5.02 TeV using charge-dependent azimuthal anisotropies