An M -automaton is a finite automaton with a blind counter that mimics a monoid M . The finitely generated groups whose word problems (when viewed as formal languages) are accepted by M -automata play a central role in understanding the family L(M ) of all languages accepted by M -automata. If G 1 and G 2 are finitely generated groups whose word problems are languages in L(M ), in general, the word problem of the free product G 1 * G 2 is not necessarily in L(M ). However, we show that if M is enlarged to the free product M * P 2 , where P 2 is the polycyclic monoid of rank two, then this closure property holds. In fact, we show more generally that the special word problem of M 1 * M 2 lies in L(M * P 2 ) whenever M 1 and M 2 are finitely generated monoids with special word problems in L(M * P 2 ). We also observe that there is a monoid without zero, denoted by CF 2 , that can be used in place of P 2 for this purpose. The monoid CF 2 is the rank two case of what we call a monoid with right invertible basis and its Rees quotient by its maximal ideal is P 2 . The fundamental theory of monoids with right invertible bases is completely analogous to that of free groups, and thus they are very convenient to use. We also investigate the questions of whether there is a group that can be used instead of the monoid P 2 in the above result and under what circumstances P 1 (or the bicyclic monoid) is enough to do the job of P 2 .