The measures of the smallest angles of three different right triangles sum to $90^\circ$. All three triangles have side lengths that are primitive Pythagorean triples. Two of them are $3-4-5$ and $5-12-13$. What is the perimeter of the third triangle?