#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

template<class T, T INF>
class Dinic {
public:
    Dinic(int n) :g(n), level(n), iter(n) {}
    void add_edge(int from, int to, T cap) {
        g[from].emplace_back(to, cap, (int)g[to].size());
        g[to].emplace_back(from, 0, (int)g[from].size() - 1);
    }
    T max_flow(int s, int t) {
        T flow = 0;
        while (true) {
            bfs(s);
            if (level[t] < 0) return flow;
            std::fill(iter.begin(), iter.end(), 0);
            T f;
            while ((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
private:
    void bfs(int s) {
        std::fill(level.begin(), level.end(), -1);
        std::queue<int> que;
        level[s] = 0;
        que.push(s);
        while (!que.empty()) {
            auto v = que.front(); que.pop();
            for (int i = 0; i < (int)g[v].size(); ++i) {
                auto& e = g[v][i];
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    T dfs(int v, int t, T f) {
        if (v == t) return f;
        for (int& i = iter[v]; i < (int)g[v].size(); ++i) {
            auto& e = g[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                auto d = dfs(e.to, t, std::min<T>(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    struct Edge {
        int to, rev; T cap;
        Edge(int t, T c, int r) :to(t), cap(c), rev(r) {}
    };
    std::vector<std::vector<Edge>> g;
    std::vector<int> level;
    std::vector<int> iter;
};

int h, w;
char a[105][105];
void solve() {
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) rep(k, w) {
        if (a[i][j] == 'S' && a[i][k] == 'T') { cout << -1 << endl; return; }
    }
    rep(k, w) rep(i, h) rep(j, h) {
        if (a[i][k] == 'S' && a[j][k] == 'T') { cout << -1 << endl; return; }
    }

    Dinic<int, iinf> dinic(h + w + 2);
    rep(i, h) rep(j, w) {
        if (a[i][j] == 'S') {
            dinic.add_edge(0, i + 1, iinf);
            dinic.add_edge(0, h + j + 1, iinf);
        }
        else if (a[i][j] == 'T') {
            dinic.add_edge(i + 1, h + w + 1, iinf);
            dinic.add_edge(h + j + 1, h + w + 1, iinf);
        }
        else if (a[i][j] == 'o') {
            dinic.add_edge(i + 1, h + j + 1, 1);
            dinic.add_edge(h + j + 1, i + 1, 1);
        }
    }
    auto ans = dinic.max_flow(0, h + w + 1);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 896