A forest is a grid of R rows and C columns. Each cell is one of: F (already burning at minute 0), T (an unburnt tree), or . (bare ground). Every minute, fire spreads from each burning cell to any tree in a directly adjacent cell (up, down, left, right); that tree begins burning. Fire never spreads onto or through bare ground.
Report the number of minutes until every tree is burning. If some tree can never catch fire, report -1. If there are no trees at all, report 0.
Input format
Line 1: two integers R and C.
Next R lines: a string of exactly C characters, each F, T, or ..
Output format
A single integer: the minutes until all trees burn, -1 if impossible, or 0 if there are no trees.
Constraints
- 1 <= R, C <= 1000
- Every grid character is
F,T, or..