Time limit
1s
Memory limit
512 MB
Captain Hook has found a rectangular treasure map divided into cells. Each cell is marked as land (L) or water (W). From a land cell, movement is allowed only to an edge-adjacent land cell, and each move takes one hour.
The treasure is buried in two land cells whose shortest travel time between them is as large as possible. Among all pairs of land cells that can reach each other, find the maximum shortest travel time.
The first line contains the height H and width W of the treasure map, separated by a space. The next H lines contain the map, using L and W with no spaces between characters.
Both the height and the width of the map are at most 50.
Print the shortest travel time between the two land cells where the treasure is buried.