Left Labyrinths

No attempts yetTime limit1sMemory limit128 MB

Problem

"The instructions to turn always to the left reminded me that such was the common procedure for discovering the central courtyard of certain labyrinths."

— Jorge Luis Borges, The Garden of Forking Paths

A fellow librarian has unearthed a vast catalogue of labyrinths, and it is our duty to classify them all. Each labyrinth plan has already been digitized into a grid of cells, where every cell is either a wall block or a piece of floor.

The walls are contiguous sequences of blocks that form horizontal or vertical corridors between them. Every labyrinth has exactly one entrance (a single opening in its exterior wall) and exactly one central courtyard. The courtyard differs from the corridors in shape: a corridor is only one cell wide, so every corridor floor cell is hemmed in by walls, whereas the courtyard is a wider open area. You may assume that each plan contains a single labyrinth and that its exterior wall can be traced completely inside the grid (there is floor all around it).

Starting at the entrance and always turning left at every intersection, you may or may not arrive at the central courtyard. Concretely, keep your left hand on the wall: at each step turn left if you can, otherwise go straight, otherwise turn right, and only turn back as a last resort. If this procedure eventually leads you into the central courtyard, the labyrinth is called a left labyrinth. Given a plan, decide whether it is a left labyrinth.

Input

The first line contains the integer n, the number of rows of the map. The second line contains the integer m, the number of characters per row. Both are smaller than 100.

Each of the following n lines contains exactly m characters, each one being either # (a block of wall) or . (a floor cell).

Output

Print YES if the given labyrinth is a left labyrinth, or NO otherwise.