#B3625. Doraemon in the Maze

    ID: 11285 Type: Default 1000ms 256MiB

Doraemon in the Maze

Doraemon in the Maze

Doraemon is trapped in a rectangular maze represented as an n×mn \times m grid. Each cell in the maze is either an empty space or a wall. Doraemon can only move from one empty cell to an adjacent empty cell in the four cardinal directions: up, down, left, and right.

The starting position is at the top-left corner, i.e. cell (1,1)(1,1), and the goal is to reach the bottom-right corner, i.e. cell (n,m)(n,m).

Determine whether Doraemon can reach the destination. If he can, print YES; otherwise, print NO.

The maze cells are given as follows: a '.' (dot) represents an empty space, and a '#' (hash) represents a wall.

inputFormat

The first line contains two integers nn and mm (1n,m1000)(1 \le n, m \le 1000), representing the number of rows and columns of the maze respectively.

Each of the following nn lines contains a string of length mm consisting of characters '.' and '#' that describe the maze.

outputFormat

Output a single line containing YES if Doraemon can go from cell (1,1)(1,1) to cell (n,m)(n,m) through empty cells only, or NO otherwise.

sample

3 3
...
.#.
...
YES