The galaxy S5 has more features than the M8 and like the finger print scanner and heart rate monitor but they are slow with system updates. I don't know how good HTC is with their updates so you will have to ask around. If you like taking a lot of night time photos and videos then the M8 wins. It also has a simpler interface than the S5.
For the screens the S5 has an amoled screen which make for more vivid colours but oversaturate them a lot where as the M8 is a bit more natural. Its up to you which you prefer
Me personally I would choose the M8 over the S5 because of its look, curved nature and metallic body.
If you had to choose a different phone it would depend on what you do with it