If M is known at the compile time, (M-1) and ~(M-1) can be pre-calculated. Then it's only two operations at run-time. You cannot do that in one operation, so it is the most efficient.
If M is unknown at the compile time, there are two more operations to compute (M-1) and ~(M-1). There are only a handful possible values for M, so you could create a table with pre-computed values, but it'll probably take longer to fetch them from the table than to calclulate. So, I think in this case it's the most efficient way too.
Why do you want this to be efficient?