#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
#define debegin printf("debug\nbegin\n")
#define deend printf("debug\nend\n")
#define isfind printf("find\n")
template<class T>inline void rread(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************	
namespace Network{
	const int maxn=100005,maxm=1000005,inf=1e9;
	int S,T;
	int head[maxn],from[maxm],des[maxm],nxt[maxm],f[maxm],tot;
	int cur[maxn],d[maxn],h[maxn],pre[maxn];
	inline void init(int _S,int _T){
		S=_S;T=_T;
		ms(head,0);tot=1;
	}
	inline void adde(int x,int y,int z){
		from[++tot]=x;des[tot]=y;f[tot]=z;nxt[tot]=head[x];head[x]=tot;
		from[++tot]=y;des[tot]=x;f[tot]=0;nxt[tot]=head[y];head[y]=tot;
	}
	inline int maxflow(int n){
		int maxflow=0,u=S;
		rep(i,1,n)pre[i]=d[i]=0,cur[i]=head[i];
		h[d[0]]=n;
		while(d[S]<n){
			if(u==T){
				int minflow=inf,re=S;
				while(u!=S){
					if(f[pre[u]]<minflow)minflow=f[pre[u]],re=from[pre[u]];
					u=from[pre[u]];
				}
				maxflow+=minflow;u=T;
				while(u!=S){
					f[pre[u]]-=minflow;
					f[pre[u]^1]+=minflow;
					u=from[pre[u]];
				}
				u=re;
			}
			bool flag=0;
			Rep2(p,u){
				if(f[p]&&d[des[p]]==d[u]-1){
					u=des[p];pre[u]=p;flag=1;break;
				}
				cur[u]=p;
			}
			if(flag)continue;
			cur[u]=head[u];int mind=n-1;
			Rep2(p,u)if(f[p]&&d[des[p]]<mind){
				mind=d[des[p]];cur[u]=p;
			}
			h[d[u]]--;if(!h[d[u]])break;
			d[u]=mind+1;h[d[u]]++;
			if(u!=S)u=from[pre[u]];
		}
		return maxflow;
	}
}
const int inf=1e9;
int n,m,sx,sy,tx,ty;
char str[105][105];
int main(){
	rread(n);rread(m);
	Network::init(n+m+1,n+m+2);
	rep(i,1,n){
		scanf("%s",str[i]+1);
		rep(j,1,m){
			if(str[i][j]=='o')Network::adde(i,j+n,1),Network::adde(j+n,i,1);
			if(str[i][j]=='S')sx=i,sy=j,Network::adde(n+m+1,i,inf),Network::adde(n+m+1,j+n,inf);
			if(str[i][j]=='T')tx=i,ty=j,Network::adde(i,n+m+2,inf),Network::adde(j+n,n+m+2,inf);
		}
	}
	if(sx==tx||sy==ty)puts("-1");
	else printf("%d\n",Network::maxflow(n+m+2));
	return 0;
}

Measured memory_bytes: 6912