Frame
The Alpha version of the "Windows 0.9" system operated solely in text mode. Its only capability was to draw windows on the screen, without the ability to remove, move, or resize them. Each window had a border made of a unique character, while the interior of the window remained unchanged from the background.
The background of "Windows 0.9" was considered exceptionally beautiful for its time, as the entire screen was filled with the character "." (dot). Consequently, during operation, the screen might appear as shown in the sample input file.
Your task is to write a program that, given the appearance of the screen, determines the order in which the windows were drawn.
Note: You can assume that each window has at least one visible character on each of its sides (left, top, right, bottom) that is not obscured by other window frames. A corner character is considered part of both adjacent sides.
Window frames are drawn using Latin letters and digits, with each window having a distinct character. Uppercase and lowercase letters are treated as different characters.
A solution is guaranteed to exist.
Input
The first line of the input file contains two numbers, N and M, representing the width and height of the screen, respectively (1 ≤ N, M ≤ 100). The subsequent lines describe the screen. There may be trailing spaces at the end of these lines, but the first N characters of each line are non-spaces.
Output
Output a single line containing the characters used for the window frames, in the order they were drawn on the screen. If there are multiple valid solutions, you may output any one of them.