Just finished my period, can I fast but do ghusl before dhuhr and then make up fajr?

I just finished my period and it’s currently 2am and I have an early class which finishes before dhuhr. Can I fast tommorow but do ghusl after my class and then make up fajr and pray dhuhr? Or will missing fajr invalidate the fast?