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

struct edge { int to, cap, rev; };

vector<edge> G[210];
int level[210];
int iter[210];
int INF = 10000000;

void add_edge(int from, int to, int cap) {
	G[from].push_back({ to, cap, (int)G[to].size() });
	G[to].push_back({ from, cap, (int)G[from].size() - 1 });
}

void add_multi_edge(int v1, int v2, int cap) {
	G[v1].push_back({ v2, cap, (int)G[v2].size() });
	G[v2].push_back({ v1, cap, (int)G[v1].size() - 1 });
}

void BFS(int S) {
	memset(level, -1, sizeof(level));
	queue<int> Q;
	level[S] = 0;
	Q.push(S);
	while (!Q.empty()) {
		int V = Q.front(); Q.pop();
		for (edge E : G[V]) {
			if (E.cap > 0 && level[E.to] < 0) {
				level[E.to] = level[V] + 1;
				Q.push(E.to);
			}
		}
	}
}

int DFS(int V, int T, int F) {
	if (V == T) return F;
	for (int& i = iter[V]; i < G[V].size(); i++) {
		edge& E = G[V][i];
		if (E.cap > 0 && level[V] < level[E.to]) {
			int D = DFS(E.to, T, min(F, E.cap));
			if (D > 0) {
				E.cap -= D;
				G[E.to][E.rev].cap += D;
				return D;
			}
		}
	}
	return 0;
}

int max_flow(int S, int T) {
	int flow = 0;
	while (1) {
		BFS(S);
		if (level[T] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int F;
		while ((F = DFS(S, T, INF)) > 0) {
			flow += F;
		}
	}
}

int main() {
	string S[100];
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == 'S') {
				add_edge(200, i, INF);
				add_edge(200, j + 100, INF);
			}
			if (S[i][j] == 'T') {
				add_edge(i, 201, INF);
				add_edge(j + 100, 201, INF);
			}
			if (S[i][j] == 'o') {
				add_multi_edge(i, j + 100, 1);
			}
		}
	}
	int ANS = max_flow(200, 201);
	if (ANS >= INF) cout << -1 << endl;
	else cout << ANS << endl;
}