Net exports term in aggregate expenditure
Seems like what you are adding up is not the Gross Domestic Product, rather something like the Gross Domestic Expenditure.
$$
C+I+G+X-M = Y = C+I+G+M-X
$$
could only possibly hold if $M - X = 0$, that is if the trade balance was zero. If this is not true, e.g., if $M - X &gt; 0$ than a country's gross expenditure is larger than its production, so counting these things will not both sum up to $Y$.