You can see a different value of M as a different algorithm. Or you can simply use the highest possible value for worst case complexity.
nM + n + M = n(1+M) + M.
For large values of N you can simplify it as
n*(1+M)
In big-O notation this is simply
O(n)