Suppose I have money ($x$) in a bank account bank with compound interest of $5\%$ annually paid monthly. Bank gives me $20,000$ usd a month and the money $x$ finishes in $20$ years ($240$ months). How to calculate how much was $x$?

For example if $x=1,000,000$, after first month the money will reduce to $x'=1,000,000+1,000,000\times 0.05\times \frac{1}{12}-20,000=984,167$.

I know how to formulate it but it's very long messy equation which I have no idea how to solve it.

Thank you