“Offer prayer on time, and if you reached the Imam leading them in prayers (on time), then perform it with them, and you will be safe with your prayer, otherwise it will be voluntary for you.”
عَنِ النَّبِيِّ ﷺ قَالَ صَلِّ الصَّلاَةَ لِوَقْتِهَا فَإِنْ أَدْرَكْتَ الإِمَامَ يُصَلِّي بِهِمْ فَصَلِّ مَعَهُمْ وَقَدْ أَحْرَزْتَ صَلاَتَكَ وَإِلاَّ فَهِيَ نَافِلَةٌ لَكَ