The chemical composition of the highest end of the ultra-high-energy cosmic ray spectrum is very hard to measure experimentally, and to this day it remains mostly unknown. Since the trajectories of ultra-high-energy cosmic rays are deflected in the magnetic field of the Galaxy by an angle that depends on their atomic number Z, it could be possible to indirectly measure Z by quantifying the amount of such magnetic deflections. In this paper we show that, using the angular harmonic cross-correlation between ultra-high-energy cosmic rays and galaxies, we could effectively distinguish different atomic numbers with current data. As an example, we show how, if Z = 1, the cross-correlation can exclude a 39% fraction of Fe56 nuclei at 2σ for rays above 100 EeV.