The first side of a triangle is 9 meters shorter than the second side. The third side is 3 times as long as the first side. The perimeter is 39 meters. Find the length of the longest side.