#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
 
const int N = 2e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
 
int ID, id[105][105];
char s[105][105];
pair<int, int> ss, tt;
 
vector<int> Eid[N];
int n, m, cnt, S, T, in[N], out[N], cur[N], d[N];
struct Edge {
	int c, v;
} E[N];
void AddEdge(int x, int y, int c) {
	E[cnt].v = y, E[cnt].c = c;
	Eid[x].push_back(cnt++);
	E[cnt].v = x, E[cnt].c = 0;
	Eid[y].push_back(cnt++);
}
bool BFS() {
	static int Q[N];
	int x, ql, qr;
	for (int i = 0; i <= T; i++) d[i] = -1;
	Q[ql = qr = 0] = S; d[S] = 0;
	while (ql <= qr) {
		x = Q[ql++];
		for (int i = 0; i < Eid[x].size(); i++) {
			const Edge &e = E[Eid[x][i]];
			if (e.c && d[e.v] == -1) {
				Q[++qr] = e.v;
				d[e.v] = d[x] + 1;
				if (e.v == T) return 1;
			}
		}
	}
	return 0;
}
int Aug(int x, int a) {
	if (x == T) return a;
	int aug = 0, delta;
	for (int &i = cur[x]; i < Eid[x].size(); i++) {
		Edge &e = E[Eid[x][i]];
		if (e.c && d[e.v] == d[x] + 1) {
			delta = Aug(e.v, min(a, e.c));
			if (delta) {
				e.c -= delta;
				E[Eid[x][i] ^ 1].c += delta;
				aug += delta;
				if (!(a -= delta)) break;
			}
		}
	}
	if (!aug) d[x] = -1;
	return aug;
}
int MaxFlow() {
	int flow = 0;
	while(BFS()) {
		for (int i = 0; i <= T; i++) cur[i] = 0;
		flow += Aug(S, inf);	
	}
	return flow;
}
 
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= m; j++) {
			if (s[i][j] == 'S') ss = mk(i, j);
			if (s[i][j] == 'T') tt = mk(i, j);
			if (s[i][j] == 'o') id[i][j] = ++ID;
		}
	}
	if (ss.first == tt.first) {
		puts("-1");
	 	return 0;
	}
	if (ss.second == tt.second) {
		puts("-1");
		return 0;
	}
	T = 2 * ID + n + m + 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != 'o') continue;
			AddEdge(id[i][j], id[i][j] + ID, 1);
			AddEdge(id[i][j] + ID, 2 * ID + i, inf);
			AddEdge(id[i][j] + ID, 2 * ID + n + j, inf);
			AddEdge(2 * ID + i, id[i][j], inf);
			AddEdge(2 * ID + n + j, id[i][j], inf);
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != 'S') continue;
		//	AddEdge(id[i][j], id[i][j] + ID, 1);
			for (int k = 1; k <= m; k++) {
				if (k == j) continue;
				if (s[i][k] == 'o') {
					AddEdge(S, id[i][k], inf);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != 'S') continue;
			//AddEdge(id[i][j], id[i][j] + ID, 1);
			for (int k = 1; k <= n; k++) {
				if (k == i) continue;
				if (s[k][j] == 'o') {
					AddEdge(S, id[k][j], inf);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != 'T') continue;
		//	AddEdge(id[i][j], id[i][j] + ID, 1);
			for (int k = 1; k <= m; k++) {
				if (k == j) continue;
				if (s[i][k] == 'o') {
					AddEdge(id[i][k] + ID, T, inf);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != 'T') continue;
			//AddEdge(id[i][j], id[i][j] + ID, 1);
			for (int k = 1; k <= n; k++) {
				if (k == i) continue;
				if (s[k][j] == 'o') {
					AddEdge(id[k][j] + ID, T, inf);
				}
			}
		}
	}
	cout << MaxFlow();
	return 0;
}

Measured memory_bytes: 55168