T C Brown and Peter Jau-shyong Shiue, A remark related to the Frobenius problem, Fibonacci Quart. 31 (1993) 32-36, MR 93k:11018 gives you what you need.
"For given $a,b$ with $(a, b) = 1$, let $NR(a, b)$ denote the set of numbers nonrepresentable in terms of $a,b$. Thus, $NR(a, b)$ is the set of all those nonnegative integers $n$ which cannot be expressed in the form $n = ax + by$, where $x,y$ are nonnegative integers. Let $$S(a,b) = \sum\{\,n : n \in NR(a,b)\,\}$$ equal the sum of the numbers nonrepresentable in terms of $a$ and $b$.... In this note we find that, in fact, $$S(a,b)={1\over12}(a-1)(b-1)(2ab-a-b-1)"$$
Note that there is no need here for $a,b$ to be prime numbers; relative primality is all that is required.
Now, you'll have to do some fiddling to get exactly what you want. You want natural numbers, while the paper is about nonnegative numbers. But if $x=0$ (resp., $y=0$), then $n$ is a multiple of $b$ (resp., $a$), and it's easy to calculate the contribution of those values to the sum.
Also, you want the difference between the representables and the nonrepresentables. But of course the sum of the representables and the nonrepresentables is just all the sum of all the integers from $1$ to your $M$, which is easy, even after you account for the ones not relatively prime to $M$, and having the sum and one of the terms you can work out the difference easily enough.
The paper is available online and is quite easy to read.
A follow-up paper, Oystein J Rodseth, A note on T. C. Brown & P. J.-S. Shiue's paper: "A remark related to the Frobenius problem", Fibonacci Quart. 32 (1994) 407-408, MR 95j:11022, evaluates the sum of the $m$th powers of the nonrepresentables for all nonnegative integers $m$.