We present a novel approach to search for origins of ultra-high energy cosmic rays. In a simultaneous fit to all observed cosmic rays we use the galactic magnetic field as a mass spectrometer and adapt the nuclear charges such that their extragalactic arrival directions are concentrated in as few directions as possible. During the fit the nuclear charges are constraint by the individual energy and shower depth measurements. Using different simulated examples we show that, with the measurements on Earth, reconstruction of extragalactic source directions is possible. In particular, we show in an astrophysical scenario that source directions can be reconstructed even within a substantial isotropic background.