A two-step optimized measurement for the phase shift