For those of us "math challanged" you denominations must not have any common factors. i.e. all even, all multiples of some
N. Otherwise there is an infinite number of prices which you can't buy:-(
In a more obscure vein. A closed solution for arbitrary M has been shown to be NP-hard.
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).