#include <bits/stdc++.h>
using namespace std;

char tmp[105];
int w[205][205];
int vs[205];

int N;

int dfs(int x){
    if(x == N) return 1;
    if(vs[x]) return 0;
    vs[x] = 1;
    for(int i=0; i<=N; i++){
        if(!w[x][i]) continue;
        int k = dfs(i);
        if(k){
            w[x][i]--;
            w[i][x]++;
            return 1;
        }
    }
    return 0;
}

int main(){
    int H, W;
    scanf("%d%d", &H, &W);
    N = H+W+1;
    int s_x=-1, s_y=-1, t_x=-1, t_y=-1;
    for(int i=1; i<=H; i++){
        scanf("%s", &tmp[1]);
        for(int j=1; j<=W; j++){
            if(tmp[j] == 'o'){
                w[i][H+j]++;
                w[H+j][i]++;
            } else if(tmp[j] == 'S'){
                w[0][i] += 1e9;
                w[0][H+j] += 1e9;
                s_x = i, s_y = j;
            } else if(tmp[j] == 'T'){
                w[H+j][N] += 1e9;
                w[i][N] += 1e9;
                t_x = i, t_y = j;
            }
        }
    }
    if(s_x == t_x || s_y == t_y){
        printf("-1");
        return 0;
    }
    int res = 0;
    while(1){
        for(int i=0; i<=N; i++) vs[i] = 0;
        int found = dfs(0);
        res += found;
        if(!found) break;
    }
    printf("%d", res);
    return 0;
}
