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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 211, M = 40013, oo = 1e9;
struct Edge {int v, w, nxt;} a[M];
int head[N], cur[N], dis[N];
char str[N];
int n, m, s, t, _ = 1;

inline void add(int x, int y, int z) {
	a[++_].v = y, a[_].w = z, a[_].nxt = head[x], head[x] = _;
	a[++_].v = x, a[_].w = 0, a[_].nxt = head[y], head[y] = _;
}

bool bfs() {
	static int q[N], he, ta;
	memset(dis, -1, t + 1 << 2);
	dis[q[he = ta = 1] = s] = 0;
	while(he <= ta) {
		int x = q[he++];
		for(int i=head[x];i;i=a[i].nxt)
			if(a[i].w > 0 and dis[a[i].v] == -1) {
				dis[a[i].v] = dis[x] + 1;
				q[++ta] = a[i].v;
				if(a[i].v == t) return true;
			}
	}
	return false;
}

int dfs(int x, int flw) {
	if(x == t or flw == 0) return flw;
	int res = 0, tmp;
	for(int&i=cur[x];i;i=a[i].nxt)
		if(dis[a[i].v] == dis[x] + 1 and a[i].w > 0)
		if(tmp = dfs(a[i].v, min(flw - res, a[i].w)))
			a[i].w -= tmp, a[i^1].w += tmp, res += tmp;
	if(!res) dis[x] = -1;
	return res;
}

int main() {
	read(n), read(m), s = n+m+1, t = s+1;
	for(int i=1;i<=n;++i) {
		scanf("%s", str+1);
		for(int j=1;j<=m;++j) {
			if(str[j] == 'o') {add(i, j+n, 1), add(j+n, i, 1); continue;}
			if(str[j] == 'S') add(s, i, +oo), add(s, j+n, +oo);
			if(str[j] == 'T') add(i, t, +oo), add(j+n, t, +oo);
		}
	}
	
	int Ans = 0;
	while(bfs()) {
		memcpy(cur, head, t + 1 << 2);
		Ans += dfs(s, +oo);
	}
	printf("%d\n", Ans > n * m ? -1 : Ans);
	return 0;
}