Calendar Fragment

Find all years from 1900 to 2100 whose generated 28 by 73 calendar contains the given small character fragment at some aligned position.

Medium5ImplementationSimulationMathNo attempts yetTime limit1sMemory limit64 MB

Problem

The calendar of some unknown year is written in a large character matrix. Every cell of the matrix holds an uppercase English letter, a digit, or a dot .. The calendar is built by these rules.

  • One month takes up exactly 8 rows and 17 columns.

    • The month name, in uppercase English, is written in the first row starting from the second column.

    • All days of the month are written in six groups that are 2 columns wide and 7 rows tall. One blank column, filled with ., separates two neighboring groups.

    • One group holds the consecutive days of a single week.

    • A day number has one or two digits. A one-digit number is written in the right column of its group.

      • The first row is Monday.
      • The first group must hold at least one day number, while the fifth and the sixth group can be empty. That happens, for example, when a month of 28 days starts on a Monday.
  • The twelve months are arranged in three bands, with one blank row between two neighboring bands. Each band holds four consecutive months, with one blank column between two neighboring months.

  • A blank margin of one row or one column runs along all four edges of the calendar.

The whole calendar is therefore exactly 28 rows and 73 columns. The image above shows the bottom right part of the calendar for 2002.

Archaeologists found one rectangular piece cut out of such a calendar. They also know that the fragment is not rotated and not changed in any other way. Write a program that finds every year from 1900 to 2100 inclusive that the fragment could have been cut from.

The English month names, in order, are JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER.

A year is a leap year if it is divisible by 400, or if it is divisible by 4 and not divisible by 100. January 1, 1900 was a Monday.

Input

The first line holds two natural numbers NN and MM (2N,M102 \le N, M \le 10), the number of rows and the number of columns of the fragment. Each of the next NN lines holds MM characters, one row of the fragment.

Output

Print every year you find in ascending order, one per line.

The input is always such that at least one answer exists.