Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3314
CAPTCHA

Time Limit: 1 Second      Memory Limit: 32768 KB

A CAPTCHA (Completely Automated Public Turing Test to Tell Computers and Humans Apart) is a program that generates and grades tests that are human solvable, but intends to be beyond the capabilities of current computer programs. This technology is now almost a standard security mechanism for defending against undesirable or malicious Internet bot programs, such as those spreading junk emails and those grabbing thousands of free email accounts instantly.

It is hard for you to make a program to solve it. So, in this moment, you just need to solve a much easier problem.

111111MMM1111111   1MMMMMMMMMMM1111   11111MMMMMMMM111   1MMMMMMMMMMM1111   1MMMMMMMMMMMM111   1MMMMMMMMMMMMM11   
11111MM1MM111111   1MM11111111MM111   111MM1111111MM11   1MM111111111MM11   1MM1111111111111   1MM1111111111111   
1111MM111MM11111   1MM11111111MM111   11MM111111111MM1   1MM1111111111MM1   1MM1111111111111   1MM1111111111111   
111MMMMMMMMM1111   1MMMMMMMMMMM1111   11MM111111111111   1MM1111111111MM1   1MMMMMMMMMMMM111   1MMMMMMMMMMMMM11   
11MM1111111MM111   1MM11111111MM111   11MM111111111MM1   1MM1111111111MM1   1MM1111111111111   1MM1111111111111   
1MMM11111111MM11   1MM11111111MM111   111MM1111111MM11   1MM111111111MM11   1MM1111111111111   1MM1111111111111   
1MM1111111111MM1   1MMMMMMMMMMM1111   11111MMMMMMMM111   1MMMMMMMMMMM1111   1MMMMMMMMMMMM111   1MM1111111111111   

11111MMMMMMMM111   1MM111111111MM11   11111MMMMMM11111   1111MMMMMMMM1111   11MM111111MMM111   11MM111111111111   
111MM1111111MM11   1MM111111111MM11   1111111MM1111111   1111111MM1111111   11MM11111MMM1111   11MM111111111111   
11MM111111111MM1   1MM111111111MM11   1111111MM1111111   1111111MM1111111   11MM111MMM111111   11MM111111111111   
11MM111111111111   1MMMMMMMMMMMMM11   1111111MM1111111   1111111MM1111111   11MMMMM111111111   11MM111111111111   
11MM111111MMMMM1   1MM111111111MM11   1111111MM1111111   111MM11MM1111111   11MM111MMM111111   11MM111111111111   
111MM1111111MM11   1MM111111111MM11   1111111MM1111111   111MMM1MM1111111   11MM11111MMM1111   11MM111111111111   
11111MMMMMMMMM11   1MM111111111MM11   11111MMMMMM11111   11111MMMM1111111   11MM111111MMMM11   11MMMMMMMMMMMM11   

1MM1111111111MM1   1MMM111111111MM1   11111MMMMMM11111   1MMMMMMMMMMM1111   11111MMMMMM11111   1MMMMMMMMMMM1111   
1MMMM111111MMMM1   1MMMM11111111MM1   111MMM1111MMM111   1MM111111111MM11   111MMM1111MMM111   1MM111111111MM11   
1MM1MM1111MM1MM1   1MM1MM1111111MM1   11MMM111111MMM11   1MM1111111111MM1   11MMM111111MMM11   1MM1111111111MM1   
1MM11MMMMM111MM1   1MM11MM111111MM1   1MM1111111111MM1   1MM111111111MM11   1MM1111111111MM1   1MM111111111MM11   
1MM1111M11111MM1   1MM1111MM1111MM1   11MMM111111MMM11   1MMMMMMMMMMM1111   11MMM1MMMM1MMM11   1MMMMMMMMMMM1111   
1MM1111111111MM1   1MM111111MMM1MM1   111MMM1111MMM111   1MM1111111111111   111MMM11MMMMM111   1MM11111111MM111   
1MM1111111111MM1   1MM11111111MMMM1   11111MMMMMM11111   1MM1111111111111   111111MMMM1MMMM1   1MM111111111MMM1   

1111MMMMMMMM1111   11MMMMMMMMMMMM11   1MM1111111111MM1   1MMMM111111MMMM1   1MM1111111111MM1   11MMM111111MMM11   
111MM1111111MM11   11MMMMMMMMMMMM11   1MM1111111111MM1   11MMM111111MMM11   1MM1111111111MM1   111MMM1111MMM111   
11MMM1111111MMM1   1111111MM1111111   1MM1111111111MM1   11MMM111111MMM11   11MM111MM111MM11   1111MMM11MMM1111   
1111MMMMM1111111   1111111MM1111111   1MM1111111111MM1   111MMM1111MMM111   11MM111MM111MM11   111111MMMM111111   
1MMM111MMMM11111   1111111MM1111111   1MMM11111111MMM1   1111MMM11MMM1111   11MM111MM111MM11   1111MMM11MMM1111   
111MMM11111MMM11   1111111MM1111111   1MMM11111111MMM1   11111MM11MM11111   11MM1MM11MM1MM11   111MMM1111MMM111   
11111MMMMMMM1111   1111111MM1111111   111MMMMMMMMMM111   111111MMMM111111   111MMM1111MMM111   11MMM111111MMM11   

11MMM111111MMM11   111MMMMMMMMMM111   
111MMM1111MMM111   1111111111MM1111   
1111MMM11MMM1111   111111111MM11111   
111111MMMM111111   11111111MM111111   
1111111MM1111111   111111MM11111111   
1111111MM1111111   11111MM111111111   
1111111MM1111111   111MMMMMMMMMMM11   

Assume that the CAPTCHA only consists of upper letters. As you see above, we use a 7 * 16 matrix to represent a letter. The matrix only consists of characters 'M' and '1'. You can make sure that the 'M' elements in each letter matrix are connected. It means the all 'M' elements in each letter matrix belong to only ONE component. One element is connected to its 8 neighboring elements. That is, (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1), (x - 1, y - 1), (x + 1, y - 1), (x - 1, y + 1), (x + 1, y + 1) are (x, y)'s neighbors and they are connected.

And you will be given a bigger matrix, like this:

11111MMMMMM111
1111111MM11111
1MM1111MM11111
1MM1111MM11111
1MM1111MM11111
1MM1111MM11111
1MM11MMMMMM111
1MM11111111111
1MMMMMMMMMMMM1

Your task is to tell which letters appear in this matrix. The answer for this sample is 'I' and 'L'.

What's more, the letter appears in the bigger matrix may rotate 180 degrees, like this:

1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM111MMMMMMMMMMMMM1
1MMM11111111MMM11111111111111MM1
1MMM11111111MMM11111111111111MM1
111MMMMMMMMMM11111MMMMMMMMMMMMM1

'F' and 'U' is the answer for this sample.

OK, it's time for you to finish this work.

Input

There are multiple cases (no more than 10). In the first line, two integers n and m (7 <= n, m <= 300) will be given. Following n lines give the matrix. Each line contains m characters. Each character will be either 'M' or '1'. You may assume that 'M' characters between any pair of letters in the matrix won't be connected, and each 'M' in the matrix belongs to one valid letter.

There is a blank line between cases.

Output

Output the characters appear in the matrix. If a letter appears more than once, just output it ONE time. Sort the answer in alphabet order.

Sample Input

7 32
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM11111111111111MM1
1MM1111111111MM111MMMMMMMMMMMMM1
1MMM11111111MMM11111111111111MM1
1MMM11111111MMM11111111111111MM1
111MMMMMMMMMM11111MMMMMMMMMMMMM1

15 19
11111MMMMMMMM111111
111MM1111111MM11111
11MM111111111MM1111
11MM111111111111111
11MM111111MMMMM1111
111MM1111111MM11111
11111MMMMMMMMM11111
1111111111111111111
1111MMM111111111MM1
1111MMMM11111111MM1
1111MM1MM1111111MM1
1111MM11MM111111MM1
1111MM1111MM1111MM1
1111MM111111MMM1MM1
1111MM11111111MMMM1

Sample Output

FU
GN

Author: LIN, Yue
Source: The 10th Zhejiang University Programming Contest
Submit    Status