For the rays to pass undeviated, the image formed by the first lens should lie at the focus of the second lens.
The first image is formed at a distance 20 cm from the first lens. and the second lens should lie at 10 cm from this point. So, the total distance = 20 +10 = 30