#include <bits/stdc++.h>


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


template<int V, class T=long long>
class max_flow {
    static const T INF = numeric_limits<T>::max();

    unordered_map<int, T> cap[V];
    int dist[V];
    bool blocked[V];

    void bfs(int s) {
        memset(dist, -1, sizeof dist);
        dist[s] = 0;
        queue<int> q;
        q.push(s);
        while (!q.empty()) {
            int n = q.front();
            q.pop();
            for (auto p : cap[n]) {
                if (p.second && dist[p.first] == -1) {
                    dist[p.first] = dist[n] + 1;
                    q.push(p.first);
                }
            }
        }
    }

    T augment(int n, T amt, int t) {
        if (n == t) return amt;
        if (blocked[n]) return 0;
        T remaining = amt;
        for (auto p : cap[n]) {
            if (dist[p.first] != dist[n] + 1) continue;
            T flowpart = min(remaining, cap[n][p.first]);
            if (flowpart) {
                T cur = augment(p.first, flowpart, t);
                remaining -= cur;
                cap[n][p.first] -= cur;
                cap[p.first][n] += cur;
            }
        }
        if (remaining) blocked[n] = true;
        return amt - remaining;
    }

public:
    void add(int u, int v, T f=1) {
        cap[u][v] += f;
    }

    T calc(int s, int t) {
        T ans = 0;
        while (true) {
            bfs(s);
            memset(blocked, false, sizeof blocked);
            T aug = augment(s, INF, t);
            if (!aug) break;
            ans += aug;
        }
        return ans;
    }

    void clear() {
        for (int i = 0; i < V; i++) {
            cap[i].clear();
        }
    }
};

max_flow<210> network;

void ins(int x, int y, ll w)
{
    network.add(x, y, w);
    network.add(y, x, w);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int h, w;
    cin>>h>>w;

    vector<string> a(h);
    for (int i = 0; i<h; i++) cin>>a[i];

    pair<int, int> s, t;
    for (int i = 0; i<h; i++)
        for (int j = 0; j<w; j++)
        {
            if (a[i][j]=='S') s = mp(i, j);
            if (a[i][j]=='T') t = mp(i, j);
        }

    if (s.first == t.first || s.second == t.second)
    {
        cout<<-1; return 0;
    }

    ins(0, s.first + 1, 1e9);
    ins(0, h + 1 + s.second, 1e9);

    ins(h+w+1, t.first + 1, 1e9);
    ins(h+w+1, h + 1 + t.second, 1e9);

    for (int i = 0; i<h; i++)
        for (int j = 0; j<w; j++) if (a[i][j]=='o') ins(1 + i, h + 1 + j, 1);

    int flow = network.calc(0, h+w+1);

    cout << flow << endl;



}


Measured memory_bytes: 1280