Each of those roads will be the hypotenuse of a right angle triangle. The first triangle has legs 1km and x km, use Pythagoras to evaluate the length of the hypotenuse. The second triangle has legs 2km and (6 - x) km. Use Pythagoras to evaluate the length of that hypotenuse. So the total length of the roads will be the sum of those hypotenuses, then find where the minimum is by setting the derivative equal to 0.
Another approach is to reflect one of the triangles across the shoreline, then simply connect the two towns with a straight line. :D