Well, BMW did offer an in warentee swapout of the block. but my research on the issue is, if it has now broken already, its not going too..
Getting back to the M5, it all depends on your personal ability and tools. Can you remove the heads yourself and reinstall, just that is like 5k worth of labour. Plenty of parts available on ebay at reasonable prices.
The funny noise could be something daft like lifters, which will not cost you a testicle, or it could be a crank that is so badly worn, you have piston slap and thats a new block, pistons, and everything else which is like a 30k rebuild.
Its the luck of the draw, my 540 i bought cheap with gearbox problems which turned out to be the alternator and cost me R400 to fix,
If the car is going to stand, you can do it yourself, and you have money to invest in the car in the long run, smartly, the M5 is probably a good deal, but not hearing that motor fire means its a game of russian roulette.