Come to prayer with calmness and tranquility. Then pray the part you get (long with the imam) and complete afterwards the part you miss. Abu Dawud said: Ibn Sirin narrated from Abu Hurairah the words: "he should complete it afterwards." Similarly, Abu Rafi' narrated from Abu Hurairah and Abu Dharr narrated from him the words "then complete it, and complete it afterwards." There is a variation of words in the narration from him. (Using translation from Abū Dāʾūd 573)
"إذا أتيتم الصلاةَ فأتُّوا وعليكم السكينةُ فصَلُّوا ما أدركتم واقضوا ما سبقكم".