#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll nn,cnt,ans,a[ohara],b,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,xx,yy;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
char c[105][105];
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

struct Graph{
    struct edge{
        int to;
        ll cap;
        ll rev;
    };

    int n;
    vector<vector<edge>> edges;

    Graph(int N){
        n = N;
        edges.resize(n, vector<edge>());
    }

    int size() const{return n;}

    vector<edge> &operator[](int v){return edges[v];}
};

struct Dinic{
    int N;
    vector<int> level;
    vector<int> itr;
    Graph G;

    Dinic(int n) : G(n){N = n;}

    void add_edge(int from, int to, ll cap, ll rev_cap){
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, rev_cap, (int)G[from].size() - 1});
    }

    bool g_level(int s, int t){
        level.assign(N, -1);
        queue<int> que;
        que.push(s);
        level[s] = 0;
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(auto &e : G[v]){
                if(e.cap > 0 && level[e.to] == -1){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
        return level[t] >= 0;
    }

    ll dfs(int v, int t, ll f){
        if(v == t)return f;

        for(int &i = itr[v]; i < G[v].size(); i++){
            auto &e = G[v][i];
            if(e.cap > 0 && level[e.to] > level[v]){
                ll mi_f = dfs(e.to, t, min(f, e.cap));
                if (mi_f > 0) {
                    e.cap -= mi_f;
                    G[e.to][e.rev].cap += mi_f;
                    return mi_f;
                }
            }
        }
        return 0;
    }

    ll max_flow(int s, int t) {
    ll result = 0;
    ll flow;
    while (g_level(s, t)) {
      itr.assign(N, 0);
      while ((flow = dfs(s, t, 1e9)) > 0)
        result += flow;
    }
    return result;
  }
};

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>c[i][j];
    int s=0,t=h+w+1;
    Dinic dinic(h+w+1+2);
    rep(i,h){
        rep(j,w){
            if(c[i][j]=='o'){
                dinic.add_edge(i+1,h+1+j,1,1);
            }
            else if(c[i][j]=='S'){
                dinic.add_edge(s,i+1,INF,INF);
                dinic.add_edge(s,h+1+j,INF,INF);
                x=j;y=i;
            }
            else if(c[i][j]=='T'){
                dinic.add_edge(i+1,t,INF,INF);
                dinic.add_edge(h+1+j,t,INF,INF);
                xx=j;yy=i;
            }
        }
    }
    if(x==xx||y==yy)Cout(-1);
    else Cout(dinic.max_flow(s,t));
    return 0;
}


Measured memory_bytes: 896