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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//{{{ Graph
typedef Int Weight;
struct Edge {
	int src, dst, rev;
	Weight weight;
	Edge(int src, int dst, Weight weight=1,int rev=-1) :
		src(src), dst(dst), weight(weight), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
		e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
//typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

struct Graph:vector<Edges>{
	Graph(){}
	Graph(const int &n){this->assign(n,Edges());}
	//add bi-directional edge
	void addBiEdge(int from ,int to, Weight w=1){
		while(this->size()<max(from,to)+1)this->push_back(Edges());
		this->at(from).push_back(Edge(from,to,w,this->at(to).size()));
		this->at(to).push_back(Edge(to,from,w,this->at(from).size()-1));
	}
	//add directional edge
	void addEdge(int from ,int to, Weight w=1){
		while(this->size()<from+1)this->push_back(Edges());
		this->at(from).push_back(Edge(from,to,w));
	}
};
#ifdef DEBUG
#include"graph/graphviz.h"
#endif
//}}}

/*
	MaxFlow mf(Graph g,int s,int t)
	mf.result
*/
//{{{ Dinic max_flow
void addFlowEdge(Graph &g,int src,int dst,Weight cap){
	while(g.size()<max(src,dst)+1)g.push_back(Edges());
	g[src].push_back(Edge(src,dst,cap,g[dst].size()));
	g[dst].push_back(Edge(dst,src,0,g[src].size()-1));
}
void addBiFlowEdge(Graph &g,int src,int dst,Weight cap){
	while(g.size()<max(src,dst)+1)g.push_back(Edges());
	g[src].push_back(Edge(src,dst,cap,g[dst].size()));
	g[dst].push_back(Edge(dst,src,cap,g[src].size()-1));
}

struct MaxFlow{
	static const Weight FLOW_INF=2e+9;
	const Graph &g;
	vector<vector<Weight> > res;
	const int n;
	vector<int> level,iter;
	Weight result;
	MaxFlow(Graph &g,int s,int t):g(g),n(g.size()){calc(s,t);}
	void bfs(vector<int> &level,int s){
		const int n=g.size();
		level.assign(n,-1);
		queue<int> q;
		level[s]=0;
		q.push(s);
		while(not q.empty()){
			int v=q.front();q.pop();
			for(int i=0;i<(int)g[v].size();i++){
				const Edge &e=g[v][i];
				if(res[v][i]>0 and level[e.dst]<0){
					level[e.dst]=level[v]+1;q.push(e.dst);
				}
			}
		}
	}
	Weight dfs(int v, int t, Weight f){
		const int n=g.size();
		if(v==t)return f;
		for(int &i=iter[v];i<(int)g[v].size();i++){
			const Edge &e=g[v][i];
			if(res[v][i]>0 and level[v]<level[e.dst]){
				Weight d=dfs(e.dst,t,min(f,res[v][i]));
				if(d>0){
					res[v][i]-=d;
					res[e.dst][e.rev]+=d;
					return d;
				}
			}
		}
		return Weight(0);
	}
	Weight calc(int s,int t){
		res.assign(n,vector<Weight>());
		REP(i,n)REP(j,g[i].size())res[i].push_back(g[i][j].weight);
		result=0;
		for(;;){
			bfs(level,s);
			if(level[t]<0)return result;
			iter.assign(n,0);
			Weight f;
			while((f=dfs(s,t,FLOW_INF))>0)result+=f;
		}
	}
	//additional feature
	bool decreaseable(int v0,int i0){
		if(res[v0][i0]>0)return true;
		vector<bool> vis(n,false);
		decrease_dfs(v0,i0,v0,vis);
		return vis[g[v0][i0].dst];
	}
	void decrease_dfs(int v0,int i0,int v,vector<bool> &vis){
		if(vis[v])return;
		vis[v]=true;
		REP(i,g[v].size()){
			if(res[v][i]==0)continue;
			decrease_dfs(v0,i0,g[v][i].dst,vis);
		}
	}
};
//}}}

char a[110][110];
int H,W;

int main(){
	cin>>H>>W;
	int s = H+W, t = s+1;
	Graph g(H+W+2);
	REP(i,H)cin>>a[i];
	REP(i,H)REP(j,W){
		if(a[i][j]=='S'){
			addFlowEdge(g,s,i,INF);
			addFlowEdge(g,s,H+j,INF);
		}else if(a[i][j]=='T'){
			addFlowEdge(g,i,t,INF);
			addFlowEdge(g,H+j,t,INF);
		}else if(a[i][j]=='o'){
			addBiFlowEdge(g,i,H+j,1);
		}
	}
	MaxFlow mf(g,s,t);
	cout<<((mf.result>=INF)?-1:mf.result)<<endl;
	return 0;
}


Measured memory_bytes: 1024