The M8 should charge fairly quick on the stock charger when things are working right, and it sounds like the OP is having slower than normal problems.
The most common culprit is a bad USB cable. They are prone to the connections getting loose in the plug or the wires breaking internally. So try a new cable and see if that works. If that doesn't, then try another charger itself. Just make sure it's rated a minimum 1.5A. You could also use a Quick Charge 2.0 (version number, not 2 amps) if you wanted the fastest charge rates.
If it's not the charger or cable, then it's phone hardware. Either the USB port itself is bad or the battery is defective. A bad port would show the same signs as a bad cable (I.e. Slow charging, losing battery power while on the charger, losing connection when plugged into a charger or computer when wiggling the plug in the port). A bad battery would only charge to a certain level and never any higher, drop power excessively fast, or the phone could shut down even if the gauge was showing plenty of life left in it but show zero when you plug it in or turn it back on.
My bet is on the cable, though. My OEM cable actually lasted me a long time, relatively speaking, giving me about a year's use out of it. Usually they're dead in a couple months and doesn't seem to matter if I bought a name brand replacement or cheap generics. Though I did run across a Dollar Tree cable that doesn't charge at full rate right from the package, which I think is just tiny power wires in it. Other than that, they all work great for a month or two before the plugs get loose or the wires break inside.