The quantum brachistochrone problem for an arbitrary spin in a magnetic field