using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC074F
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = ReadInt();
            int H = HW[0];
            int W = HW[1];

            char[,] map = new char[H, W];
            for (int i = 0; i < H; i++)
            {
                var s = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    map[i, j] = s[j];
                }
            }

            //最小カット
            FordFulkerson fd = new FordFulkerson(H + W + 2);
            int sh = -1, sw = -1, th = -1, tw = -1;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (map[i, j] == 'o')
                    {
                        fd.AddEdge(i, H + j, 1);
                        fd.AddEdge(H + j, i, 1);
                    }
                    if (map[i, j] == 'S')
                    {
                        sh = i; sw = j;
                        fd.AddEdge(H + W, i, int.MaxValue / 2);
                        fd.AddEdge(H + W, H + j, int.MaxValue / 2);
                    }
                    if (map[i, j] == 'T')
                    {
                        th = i; tw = j;
                        fd.AddEdge(i, H + W + 1, int.MaxValue / 2);
                        fd.AddEdge(H + j, H + W + 1, int.MaxValue / 2);
                    }
                }
            }

            var ans = fd.MaxFlow(H + W, H + W + 1);
            if (sh == th || sw == tw) ans = -1;

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
    class FordFulkerson//最大流
    {
        public struct Edge
        {
            public int to, cap, rev;
        }

        public List<Edge>[] G;
        bool[] used;
        int INF = 1000000009;

        public FordFulkerson(int V) //頂点数
        {
            G = new List<Edge>[V].Select(x => new List<Edge>()).ToArray();
            used = new bool[V];
        }

        public void AddEdge(int from, int to, int cap)
        {
            G[from].Add(new Edge() { to = to, cap = cap, rev = G[to].Count });
            G[to].Add(new Edge() { to = from, cap = 0, rev = G[from].Count - 1 });
        }

        int Dfs(int v, int t, int f)
        {
            if (v == t)
                return f;
            used[v] = true;

            for (int i = 0; i < G[v].Count; i++)
            {
                var e = G[v][i];
                if (!used[e.to] && e.cap > 0)
                {
                    int d = Dfs(e.to, t, Math.Min(f, e.cap));
                    if (d > 0)
                    {
                        e.cap -= d;
                        G[v][i] = e;

                        var temp = G[e.to][e.rev];
                        temp.cap += d;
                        G[e.to][e.rev] = temp;

                        return d;
                    }
                }
            }
            return 0;
        }

        public int MaxFlow(int s, int t)
        {
            int flow = 0;
            while (true)
            {
                used = new bool[used.Length];
                int f = Dfs(s, t, INF);
                if (f == 0) return flow;
                flow += f;
            }
        }
    }
}


Measured memory_bytes: 13524