sorting rm and rsm