Hyunwoo the wolf is running away from hunters and wants to reach a cabin in the forest. The hunters hide behind trees, so Hyunwoo wants to choose a route that stays as far from trees as possible.
The forest is represented as an N×M grid. A cell is marked . if it is empty pasture, + if it contains a tree, V for Hyunwoo's current position, and J for the cabin. Hyunwoo may move from his current cell to one of the four adjacent cells sharing an edge. He may also move onto cells that contain trees.
If Hyunwoo is currently at row R, column C, and a tree is at row A, column B, their distance is |R-A| + |C-B|.
The safety of a route is the minimum, over every cell on the route, of that cell's distance to the nearest tree. The cabin cell is also part of the route and must be included in this minimum. Find the maximum possible safety among all routes from V to J.
The first line contains two integers N and M (1 ≤ N, M ≤ 500).
Each of the next N lines contains the forest map. The map contains exactly one V, exactly one J, and at least one +.
Print one integer: the largest possible minimum distance to a tree along a route from Hyunwoo's starting cell to the cabin.