{"raw_statement":[{"iden":"problem statement","content":"There is a pond with a rectangular shape. The pond is divided into a grid with $H$ rows and $W$ columns of squares. We will denote the square at the $i$\\-th row from the top and $j$\\-th column from the left by $(i,\\ j)$.\nSome of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, $S$, there is a frog trying to get to another leaf $T$. The state of square $(i,\\ j)$ is given to you by a character $a_{ij}$, as follows:\n\n*   `.` : A square without a leaf.\n*   `o` : A square with a leaf floating on the water.\n*   `S` : A square with the leaf $S$.\n*   `T` : A square with the leaf $T$.\n\nThe frog will repeatedly perform the following action to get to the leaf $T$: \"jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located.\"\nSnuke is trying to remove some of the leaves, other than $S$ and $T$, so that the frog cannot get to the leaf $T$. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove."},{"iden":"constraints","content":"*   $2 ≤ H, W ≤ 100$\n*   $a_{ij}$ is `.`, `o`, `S` or `T`.\n*   There is exactly one `S` among $a_{ij}$.\n*   There is exactly one `T` among $a_{ij}$."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$H$ $W$\n$a_{11}$ $...$ $a_{1W}$\n$:$\n$a_{H1}$ $...$ $a_{HW}$"},{"iden":"sample input 1","content":"3 3\nS.o\n.o.\no.T"},{"iden":"sample output 1","content":"2\n\nRemove the upper-right and lower-left leaves."},{"iden":"sample input 2","content":"3 4\nS...\n.oo.\n...T"},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"4 3\n.S.\n.o.\n.o.\n.T."},{"iden":"sample output 3","content":"\\-1"},{"iden":"sample input 4","content":"10 10\n.o...o..o.\n....o.....\n....oo.oo.\n..oooo..o.\n....oo....\n..o..o....\no..o....So\no....T....\n....o.....\n........oo"},{"iden":"sample output 4","content":"5"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}