#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



struct Ford_Fulkerson{

	struct f_edge {
		ll to;
		ll cap;
		ll fl;
		ll rev;//反対方向の辺の添え字
	};


	ll N;
	ll s, t;
	vector<vector<edge>> g;//グラフ片方向にのみ張る、flowで双方向に構築
	vector<vector<f_edge>> flow;
	ll maxflow;
	
	vector<bool> see;
	ll dfs(ll v, ll x) {
		see[v] = 1;

		if (v == t) { return x; }

		rep(i,flow[v].size()) {
			const auto e = flow[v][i];

			if (see[e.to] == 1) { continue; }
			if (e.cap == e.fl) { continue; }

			ll y = min(x, e.cap - e.fl);

			y = dfs(e.to, y);
			if (y == 0) { continue; }

			flow[v][i].fl += y;
			flow[e.to][e.rev].fl -= y;
			return y;
		}

		return 0;
	}

	Ford_Fulkerson(ll N0, vector<vector<edge>> g0, ll s0, ll t0) {
		N = N0;
		g = g0;
		s = s0;
		t = t0;

		flow.resize(N + 1);
		repn(v, N) {
			for (edge e : g[v]) {
				ll w = e.to;
				flow[v].push_back({ w,e.d,0,flow[w].size() });
				flow[w].push_back({ v,e.d,0,flow[v].size() - 1 });
			}
		}

		maxflow = 0;

		if (s == t) { maxflow = INF; return; }

		while (1) {
			see.assign(N + 1, 0);
			ll f = dfs(s, INF);
			if (f == 0) {break; }
			maxflow += f;
		}

		maxflow = min(INF, maxflow);

		return;

	}	
};



int main() {

	ll H, W;
	cin >> H >> W;

	vector<vector<char>> a(H + 1, vector<char>(W + 1));

	repn(i, H)repn(j, W) cin >> a[i][j];

	vector<vector<edge>> g(H + W + 1);
	ll s;
	ll t;

	repn(i, H)repn(j, W) {
		if (a[i][j] == 'o') { g[i].push_back({ 0,i,H + j,1 }); }
		else if (a[i][j] == 'S') { g[i].push_back({ 0,i,H + j,INF }); s = i; }
		else if (a[i][j] == 'T') { g[i].push_back({ 0,i,H + j,INF }); t = H + j; }

	}

	Ford_Fulkerson ff(H+W, g, s, t);
	ll ans = ff.maxflow;
	if (ans == INF) { ans = -1; }
	cout << ans << endl;
	

	
	system("PAUSE");
}


Measured memory_bytes: 2424