Let me try to give you the low down on the E39 M5.
Great car, very fast, extremely comfortable/practical/whatever superlative you want to throw at it, but like others have said, not cheap to fix. Are you mechanically inclined? Do you plan on doing repairs yourself, or are you going to take it to a shop? From what I've heard, if you start out with a decent example, you should budget an average of about $1500-$2000 per year in maintenance cost. That number goes down a little if you do everything yourself, but it still isn't cheap.
Mechanically, the S62 is more reliable than what a lot of people say. The VANOS system can be a bitch if it goes wrong, but from what I've heard, it's usually the solenoid rather than the entire system that's failed (much cheaper and easier fix). Back when these cars were still under warranty, a lot of dealers just replaced the whole system, less diagnostic headaches that way. Otherwise, some people have started recommending replacing engine rod bearings preventively at around 100k miles. Some cars are showing more wear than others for the bearings, but if they do fail (which has on some cars), it'll throw a rod and you are most likely going to be looking for a new engine, which, you can imagine, is a lot...
Some other things to consider: depending on where the car is from, look for rust damage. The rear door vapor barriers have a tendency to let moisture in after a few years (it's a quick and easy fix), the rear sway bar mounting brackets are weak and it's not uncommon for them to be broken (install an aftermarket reinforced bracket), secondary air pump breaks, and when it does, it throws a CEL and is very expensive to repair (it helps with cold start emissions, most people just turn off the CEL rather than fixing the secondary air pump). When purchasing, check that the O2 sensor, mass airflow sensor (MAF sensor) and spark plugs have been replaced. Check to see when the clutch was replaced last, if driven hard, M5s will eat clutches every 50-60k miles or so. Expect about a quart of oil consumption every 5-7k miles. Make sure that when oil changes are done, the previous owner has used either 5W30 or 10W60. Check for weeping diff seals, hoses, suspension bushings, etc.
If you do buy an M5, the US got them from 2000-2003 model years. 2001-2003 are the post-facelift models, and there were continuous updates throughout its lifetime. Post facelift models generally fetch more money. Pre-facelift models didn't have Angel Eye lights nor Jeweled tailights, had a older navigation system with 4:3 screen, slightly different interior combo options and trim, different steering wheel and black dash gauge faces. Mechanically, a post 3/2000 build vehicle should have an updated VANOS system (desirable). Between 2001-2003, most things stayed the same. Only differences is that the rear side airbags were disabled by default for 2002 model year, 2002-2003 model years have automatic headlights, 2003 have an updated DVD based navigation system (which also allows easy plug-and-play connectivity with BMW Aux input and Bluetooth), and 2003 also had a slightly updated VANOS system that helped decrease the start-up engine ticking noise. Otherwise, all cars came pretty fully loaded and only had a few options. (It's been a while, so I may have forgotten a couple of things).
For a higher mileage 2000, you can expect to pay about $13k-$15k. Higher mileage 01-03, $18k-$20k. Lower mileage 2000, around $18-$21k. Lower mileage 01-03, $23k-$27k. Low mileage 01-03, up to $30k or so. Almost brand new 01-03, up to $45k.