#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

struct Edge {
  int to, cap, rev;
  Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
  Edge() {}
};

#define MAX_N 20010

class Dinic {
  vector<Edge> g[MAX_N];
  int level[MAX_N], iter[MAX_N];
  int dist[MAX_N];
  int flow, n;
  int st, en;
  map<P, int> edges;

  void bfs(int s) {
    rep(i, n) level[i] = -1, dist[i] = INF;
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      rep(i, g[v].size()) {
        Edge &e = g[v][i];
        if(e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          dist[e.to] = mind(e.cap, dist[v]);
          que.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, mind(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

public:
  Dinic(int n, int s, int t) {
    flow = 0;
    st = s; en = t;
    this->n = n;
  }

  // 有効辺の追加
  void add_edge(int from, int to, int cap) {
    edges[P(from, to)] = g[from].size();
    g[from].push_back(Edge(to, cap, g[to].size()));
    edges[P(to, from)] = g[to].size();
    g[to].push_back(Edge(from, 0, g[from].size()-1));
  }

  // 無向辺の追加
  void add_multi_edge(int v1, int v2, int cap) {
    edges[P(v1, v2)] = g[v1].size();
    g[v1].push_back(Edge(v2, cap, g[v2].size()));
    edges[P(v2, v1)] = g[v2].size();
    g[v2].push_back(Edge(v1, cap, g[v1].size()-1));
  }

  // 最大流を求める
  int max_flow(int s = -1, int t = -1, int rest = -1) {
    if(s == -1) s = st;
    if(t == -1) t = en;
    int su = 0;
    while(rest) {
      bfs(s);
      if(level[t] < 0) break;
      rep(i, n) iter[i] = 0;
      int f;
      while(rest && (f = dfs(s, t, rest == -1 ? INF : rest)) > 0) {
        if(rest == -1) {
          flow += f;
        } else {
          rest -= f;
        }
        su += f;
      }
    }
    return rest == -1 ? flow : su;
  }
};

int h, w;
int sx, sy, tx, ty;
#define HW 105
char cs[HW][HW];

int main() {
  cin >> h >> w;
  int start = h+w, end = h+w+1;
  Dinic d(h + w + 2, start, end);
  rep(i, h) rep(j, w) {
    cin >> cs[i][j];
    if(cs[i][j] == 'S') {
      sx = j; sy = i;
    }
    if(cs[i][j] == 'T') {
      tx = j; ty = i;
    }
  }
  rep(i, h) {
    rep(j, w) {
      char c = cs[i][j];
      switch(c) {
        case 'o':
          d.add_multi_edge(i, h + j, 1);
          break;
        case 'S':
          d.add_edge(start, i, INF);
          d.add_edge(start, h + j, INF);
          break;
        case 'T':
          d.add_edge(i, end, INF);
          d.add_edge(h + j, end, INF);
          break;
      }
    }
  }
  ll ans = d.max_flow();
  if(ans >= INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2304