A trader bought x mangoes at the rate of 4 mangoes for 10 naira, five of the mangoes were bad so he sold the remaining at the rate of 5 mangoes for 20 naira and he made a gain of 10 naira how many mangoes did he buy?