//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
bool DD=0;
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
 
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=2e2+10;

	int hou[N];
    struct Edge{int y,c,g;}e[N*N];
    int ln;int oth(int x){return x&1?x+1:x-1;}
    void ins(int x,int y,int c)
    {
        e[++ln]=(Edge){y,c,hou[x]};hou[x]=ln;
        e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln;
    }
    int st,ed;
    int h[N],cur[N];queue<int> q;
    bool bfs()
    {
    //	memset(cur,0,sizeof cur);
		memcpy(cur,hou,sizeof hou);
        memset(h,0,sizeof h);
        h[st]=1;q.push(st);
        while(q.size())
        {
            int x=q.front();q.pop();
            for(int k=hou[x];k>0;k=e[k].g)
            {
                int y=e[k].y;
                if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y);
            }
        }
        return h[ed]>0;
    }
    int dfs(int x,int ff)
    {
        if(x==ed) return ff;
		debug("dfs %d,%d\n",x,ff);
        int flow=0;
        for(int k=cur[x];k>0;k=e[k].g)
        {
            int y=e[k].y;
            if(h[y]==h[x]+1 and e[k].c>0)
            {
                int out=dfs(y,min(e[k].c,ff-flow));
                e[k].c-=out;e[oth(k)].c+=out;flow+=out;
            }
            if(e[k].c==0) cur[x]=e[k].g;
            if(flow==ff) break;
        }
        if(ff==0) h[x]=0;
		debug("ed dfs %d,%d=%d\n",x,ff,flow);
        return flow;
    }
	char mp[N][N];
	void main()
	{
		int n=qread(),m=qread();fo(i,1,n) scanf("%s",mp[i]+1);
		st=0,ed=n+m+1;
		pii S,T;
		fo(i,1,n) fo(j,1,m)
			if(mp[i][j]=='S') S={i,j},ins(st,i,INF),ins(st,n+j,INF);
			else if(mp[i][j]=='T') T={i,j},ins(i,ed,INF),ins(n+j,ed,INF);
			else if(mp[i][j]=='o') ins(i,n+j,1),ins(n+j,i,1);
		if(S.FR==T.FR or S.SE==T.SE) {puts("-1");return;}
		int ans=0;while(bfs()) ans+=dfs(st,INF);write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
	//freopen("a.in","r",stdin);
	srand(time(0));
	mine::main();
}

Measured memory_bytes: 768