#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
template<class V> struct MaxFlow {
    struct edge { int to, reve; V cap; edge(int t, int r, V c) : to(t), reve(r), cap(c) {} };
    int MV; vector<vector<edge>> E; vector<int> itr, lev;
    MaxFlow(int n) { init(n); } MaxFlow() { }
    void init(int n) { MV = n; itr = vector<int>(MV), lev = vector<int>(MV); E = vector<vector<edge>>(MV); }
    void add_edge(int x, int y, V cap, bool undir = false) {
        E[x].push_back(edge(y, (int)E[y].size(), cap));
        E[y].push_back(edge(x, (int)E[x].size() - 1, undir ? cap : 0));
    }
    void bfs(int cur) {
        rep(i, 0, MV) lev[i] = -1; queue<int> q; lev[cur] = 0; q.push(cur);
        while (q.size()) {
            int v = q.front(); q.pop();
            for (auto e : E[v]) if (e.cap>0 && lev[e.to]<0) lev[e.to] = lev[v] + 1, q.push(e.to);
        }
    }
    V dfs(int from, int to, V cf) {
        if (from == to) return cf;
        for (; itr[from]<E[from].size(); itr[from]++) {
            edge* e = &E[from][itr[from]]; if (e->cap>0 && lev[from]<lev[e->to]) {
                V f = dfs(e->to, to, min(cf, e->cap));
                if (f>0) { e->cap -= f; E[e->to][e->reve].cap += f; return f; }
            }
        } return 0;
    }
    V maxflow(int from, int to) {
        V fl = 0, tf;
        while (1) {
            bfs(from); if (lev[to]<0) return fl;
            rep(i, 0, MV) itr[i] = 0; while ((tf = dfs(from, to, numeric_limits<V>::max()))>0) fl += tf;
        }
    }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int H, W;
string A[100];
//---------------------------------------------------------------------------------------------------
vector<int> tate[101], yoko[101];
int solve() {
    int sx, sy, tx, ty;
    rep(y, 0, H) rep(x, 0, W) {
        if (A[y][x] == 'S') sx = x, sy = y, tate[x].push_back(y), yoko[y].push_back(x);
        if (A[y][x] == 'T') tx = x, ty = y, tate[x].push_back(y), yoko[y].push_back(x);
        if (A[y][x] == 'o') tate[x].push_back(y), yoko[y].push_back(x);
    }

    if (sx == tx) return -1;
    if (sy == ty) return -1;

    MaxFlow<int> mf(H * W * 2);
    rep(y, 0, H) if(2 <= yoko[y].size()){
        rep(i, 0, yoko[y].size()) rep(j, 0, yoko[y].size()) if(i != j){
            mf.add_edge(y * W + yoko[y][i], y * W + yoko[y][j] + H * W, 1);
        }
    }
    rep(x, 0, W) if (2 <= tate[x].size()) {
        rep(i, 0, tate[x].size()) rep(j, 0, tate[x].size()) if(i != j){
            mf.add_edge(tate[x][i] * W + x, tate[x][j] * W + x + H * W, 1);
        }
    }
    rep(x, 0, W) rep(y, 0, H) mf.add_edge(y * W + x + H*W, y * W + x, 1);

    return mf.maxflow(sy * W + sx, ty * W + tx + W * H);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) cin >> A[y];
    cout << solve() << endl;
}

Measured memory_bytes: 61824