Signal Spread
A grid of sensor nodes: S already has the signal, o is a node without it, . is empty. Every second, each node with the signal passes it to its up/down/left/right neighbours. After how many seconds do all nodes have the signal? Print -1 if some node never gets it.
Input
and , then lines of characters.
Output
The number of seconds, or -1.
Constraints
Sample 1
Input
3 3 Soo oo. .oo
Output
4
Sample 2
Input
3 3 Soo .oo o.o
Output
-1