active directory group membership sync base on xOrigin

Hi

Can anyone please help me out of the below requirement. 

During the active directory group sync, I want to delete all the direct (Xorigin = 1) membership from 1IM if memberships are not present in AD however if memberships are indirect (xOrigin> 1) then I want to add the membership in AD?

Thanks in advance.