#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


struct dinic{
	typedef int flow_type;

	struct edge{
		int to;
		flow_type cap;
		int rev;
		edge(int t, flow_type c, int r) : to(t), cap(c), rev(r) {}
	};

	vector<vector<edge> > gr;
	vector<int> level;
	vector<int> iter;

	dinic(){}
	dinic(int m) : gr(m), level(m), iter(m) {}
	
	size_t size() const{
		return level.size();
	}

	void initialize(int m){
		*this = dinic(m);
	}

	void add_edge(int from, int to, flow_type cap) {
		gr[from].push_back(edge(to, cap, gr[to].size()));
		gr[to].push_back(edge(from, 0, gr[from].size() - 1));
	}

	void bfs(int s){
		level.assign(level.size(), -1);
		queue<int> qu;
		level[s] = 0;
		qu.push(s);
		while(!qu.empty()){
			int v = qu.front();
			qu.pop();
			for(int i = 0; i < (int)gr[v].size(); i++){
				edge &e = gr[v][i];
				if(e.cap > 0 && level[e.to] < 0){
					level[e.to] = level[v] + 1;
					qu.push(e.to);
				}
			}
		}
	}

	flow_type dfs(int v, int t, flow_type f){
		if(v == t){
			return f;
		}
		for(int &i = iter[v]; i < (int)gr[v].size(); i++){
			edge &e = gr[v][i];
			if(e.cap > 0 && level[v] < level[e.to]){
				flow_type d = dfs(e.to, t, min(f, e.cap));
				if(d > 0){
					e.cap -= d;
					gr[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	flow_type max_flow(int s, int t){
		flow_type flow = 0;
		const flow_type INF = numeric_limits<flow_type>::max();
		for(;;){
			bfs(s);
			if(level[t] < 0){
				return flow;
			}
			iter.assign(iter.size(), 0);
			flow_type f;
			while((f = dfs(s, t, INF)) > 0) {
				flow += f;
			}
		}
	}
};

void mainmain(){
	const int INF = 1000000;

	int h, w;
	cin >> h >> w;
	vector<string> as(h);
	for(int i = 0; i < h; ++i){
		cin >> as[i];
	}
	
	dinic dn(h + w + 5);
	int src = h + w + 2;
	int sink = src + 1;
	for(int i = 0; i < h; ++i)
	for(int j = 0; j < w; ++j){
		char c = as[i][j];
		if(c == 'o'){
			dn.add_edge(i, j + h, 1);
			dn.add_edge(j + h, i, 1);
		}
		else if(c == 'S'){
			dn.add_edge(src, i, INF);
			dn.add_edge(src, j + h, INF);
		}
		else if(c == 'T'){
			dn.add_edge(i, sink, INF);
			dn.add_edge(j + h, sink, INF);
		}
	}
	
	int ans = dn.max_flow(src, sink);
	if(ans >= INF){ ans = -1; }
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 896