#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
struct edge{ ll to; ll cap; ll rev;};
vector<edge> G[11000];

bool used[11000];

void addEdge0(ll from, ll to, ll cap){
    edge A={to,cap,(ll)G[to].size()};
    edge B={from,0,(ll)G[from].size()};
    G[from].push_back(A);
    G[to].push_back(B);
    return;
}//有向グラフを作る

void addEdge1(ll a, ll b, ll cap){
    edge A={b,cap,(ll)G[b].size()};
    edge B={a,cap,(ll)G[a].size()};
    G[a].push_back(A);
    G[b].push_back(B);
    return;
}//無向グラフを作る

ll dfs(ll v, ll t, ll f){
    if(v==t) return f;
    used[v]=true;
    rep(i,G[v].size()){
        edge &e=G[v][i];
        if(!used[e.to] && e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int main(){
    ll H,W; cin>>H>>W;
    ll S,T;
    REP(i,1,H+1) REP(j,1,W+1){
        char x; cin>>x;
        ll K=j+(102*i);
        if(x=='o'){
            addEdge1(K,102*i,1);
            addEdge1(K,j,1);
        }
        if(x=='S') {
            S=K;
            addEdge1(K,102*i,INF);
            addEdge1(K,j,INF);
        }
        if(x=='T') {
            T=K;
            addEdge1(K,102*i,INF);
            addEdge1(K,j,INF);
        }
    }

    if(S%102==T%102) cout<<-1<<endl;
    else if(S/102==T/102) cout<<-1<<endl;
    else{
        ll ans=0;
        while(true){
            rep(i,11000) used[i]=false;
            ll P=dfs(S,T,INF);
            if(P==0) break;
            ans+=P;
        }
        cout<<ans<<endl;
    }
}

