It is narrated from Sayyiduna Anas (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you comes to the prayer, let him walk with dignity and calm, then let him pray whatever part of the prayer he catches (with the imam), and let him complete (afterwards) whatever part he missed."
Related hadith on this topic