All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
If you intended to pray behind the imaam who is leading the Maghrib prayer, then this is enough and your prayer is valid, and the fact that you did not designate the imaam (in your intention) does not harm; rather, the intention of praying behind the present imaam is sufficient.
The Kuwaiti Fiqh Encyclopedia reads, “The scholars of Fiqh agreed that the person led in prayer must intend to follow the imaam, but he is not obliged to designate him.”
Allah knows best.