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).

Some 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:

* `.` : A square without a leaf.
* `o` : A square with a leaf floating on the water.
* `S` : A square with the leaf S.
* `T` : A square with the leaf T.



The 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."

Snuke 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.

Constraints

* 2 ≤ H, W ≤ 100
* a_{ij} is `.`, `o`, `S` or `T`.
* There is exactly one `S` among a_{ij}.
* There is exactly one `T` among a_{ij}.

Input

Input is given from Standard Input in the following format:


H W
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}


Output

If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print `-1` instead.

Examples

Input

3 3
S.o
.o.
o.T


Output

2


Input

3 4
S...
.oo.
...T


Output

0


Input

4 3
.S.
.o.
.o.
.T.


Output

-1


Input

10 10
.o...o..o.
....o.....
....oo.oo.
..oooo..o.
....oo....
..o..o....
o..o....So
o....T....
....o.....
........oo


Output

5
import java.io.*;
import java.util.*;
import java.math.*;
// import java.awt.Point;
 
public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";
 
    long MOD = 1_000_000_007;
    int inf = Integer.MAX_VALUE/2;


    void solve(){
        int h = ni();
        int w = ni();
        char[][] map = nm(h,w);
        Dinic dinic = new Dinic(h+w);
        int s = h+w;
        int t = h+w+1;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j]=='S'){
                    dinic.addEdge(s,i,inf);
                    dinic.addEdge(s,j+h,inf);
                }
                if(map[i][j]=='T'){
                    dinic.addEdge(i,t,inf);
                    dinic.addEdge(j+h,t,inf);
                }
                if(map[i][j]=='o'){
                    dinic.addBiEdge(i,j+h,1);
                }
            }
        }
        long res = dinic.getMaxFlow(s,t);
        out.println((res>=inf ? -1 : res));


    }

    class Dinic {
        class Edge {
            int to, cap;
            int flow = 0;
            Edge rev;
            
            Edge(int to, int cap) {
                this.to = to;
                this.cap = cap;
            }
            
            void setRevEdge(Edge rev) {
                this.rev = rev;
            }
        }
        
        int N;
        int tank;
        int[] ptr, Q, dist;
        
        ArrayList<Edge>[] g;

        public Dinic(int N) {
            this.N = N;
            g = new ArrayList[N + 2];
            for (int i = 0; i < N + 2; i++)
                g[i] = new ArrayList<Edge>();
            
            ptr = new int[N + 2];
            Q = new int[N + 2];
            dist = new int[N + 2];
        }
        
        public void addEdge(int from, int to, int cap) {
            Edge e1 = new Edge(to, cap);
            Edge e2 = new Edge(from, 0);
            e1.setRevEdge(e2);
            e2.setRevEdge(e1);
            g[from].add(e1);
            g[to].add(e2);
        }
        
        boolean dinic_bfs(int src)  {
            Arrays.fill(dist, -1);
            dist[src] = 0;
            int sizeQ = 0;
            Q[sizeQ++] = src;
            for (int i = 0; i < sizeQ; i++) {
                int u = Q[i];
                for (Edge e : g[u]) {
                    if (dist[e.to] < 0 && e.flow < e.cap) {
                        dist[e.to] = dist[u] + 1;
                        Q[sizeQ++] = e.to;
                    }
                }
            }
            return dist[tank] >= 0;
        }
        
        int dinic_dfs(int u, int f) {
            if (u == tank) return f;
            for ( ; ptr[u] < g[u].size(); ptr[u]++) {
                Edge e = g[u].get(ptr[u]);
                if (dist[e.to] == dist[u] + 1 && e.flow < e.cap) {
                    int df = dinic_dfs(e.to, Math.min(f, e.cap - e.flow));
                    if (df > 0) {
                        e.flow += df;
                        e.rev.flow -= df;
                        return df;
                    }
                }
            }
            
            return 0;
        }
        
        public int getMaxFlow(int src, int tank) {
            this.tank = tank;
            
            int res = 0;
            while (dinic_bfs(src)) {
                Arrays.fill(ptr, 0);
                while (true) {
                    int df = dinic_dfs(src, Integer.MAX_VALUE);
                    if (df == 0) break;
                    res += df;
                }
            }
            
            return res;
        }

        public void addBiEdge(int from, int to, int cap) {
            Edge e1 = new Edge(to, cap);
            Edge e2 = new Edge(from, cap);
            e1.setRevEdge(e2);
            e2.setRevEdge(e1);
            g[from].add(e1);
            g[to].add(e2);
        }
    }    

    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
 
}