There is no real single answer to this question. There are a number of possible solutions that have to do with adding days. Out solution has been to add one day every four years, except in century years unless it is also a millenium!
Other cultures working off lunar calendars have added extra months about every three years. Some cycles are even more complex.
he important thing is to work out mothematically what the relationship is between the lunar cycle and the solar cycle. You can of course, simply ignore the moon and just work on the solar cycle which will work quite well and is basically what happens here - but it is much nicer to be able to loko up at the moon and know where in the month you are!