100 atcoder#ABC151D. [ABC151D] Maze Master

[ABC151D] Maze Master

Score : 400400 points

Problem Statement

Takahashi has a maze, which is a grid of H×WH \times W squares with HH horizontal rows and WW vertical columns.

The square at the ii-th row from the top and the jj-th column is a "wall" square if SijS_{ij} is #, and a "road" square if SijS_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

  • 1H,W201 \leq H,W \leq 20
  • SijS_{ij} is . or #.
  • SS contains at least two occurrences of ..
  • Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

HH WW

S11S_{11}......S1WS_{1W}

::

SH1S_{H1}......SHWS_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

3 3
...
...
...
4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

3 5
...#.
.#.#.
.#...
10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.