Algorithm 1.