Ouch! I take it was much more expensive than usual economy tickets.
What if you planned to buy a train ticket to leave? I don't know about HK but in China it's a mess since it can only be done a few weeks before the travel date and might not even have been possible to do prior to entering the country.
Actually, I didn't have to buy a ticket to leave immediately, I just had to prove I had a return ticket. I just bought the cheapest one close to the date when my tourist visa would expire. I think it was around $600.
There is no train that connects Japan to another country that I know of.