Question: Calculate the Fourier series of f (x) = e^x on the interval −π ≤ x ≤ π.
I am new to Fourier Series. I managed to find a0 and am. However, I have no idea where does the second am comes from(see solution attached). Could someone please explain what is happening in the second am?

First equality: Use the Definition of the Fourier Expansion coefficients, here $a_m$ are the cosine coefficients.
2nd equality: Integration by parts where the cosine is integrated.
3rd equality: Again it is integrated by parts; the sine function is integrated here.
4th equality: Because you have the Expression $\int_{- \pi}^\pi e^x cos(mx)dx = a_m$ again.
You can make some Manipulation with your equation; Hint: compare first line for $a_m$ with the 4th line. Then you obtained the desired result.