Effective spin-glass Hamiltonian for the anomalous dynamics of the HMF model