#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct edge
{
  int a,b;
  ll c,f;
  edge(int u,int v,ll cap):a(u),b(v),c(cap),f(0){}
};
const int L=10005;
struct flow
{
  const static ll inf = 1e18;//set s=source,t=sink,nodeCt
  int Dlevel[L],Dptr[L],s,t,nodeCt;
  queue<int> Q;
  vector<edge> E;vi ad[L] ;
  void addedge(int a,int b,int c,bool directed=true)
  {
    if(a==b)return ;//1 based index
    ad[a].pb(sz(E)),E.pb(edge(a,b,c));
    ad[b].pb(sz(E)),E.pb(edge(b,a,directed?0:c));
  }
  bool Dbfs(void)
  {
    FEN(i,nodeCt)Dlevel[i]=0;Q.push(s),Dlevel[s]=1;
    while(!Q.empty())
      {
	int levelsz=sz(Q),v;
	while(levelsz--)
	  {
	    v=Q.front();Q.pop() ;
	    for(auto &e:ad[v])
	      if(!Dlevel[E[e].b]&&E[e].f<E[e].c)
		{
		  Dlevel[E[e].b]=Dlevel[v]+1;
		  Q.push(E[e].b);
		}
	  }
      }
    return Dlevel[t]>0;
  }//by default edges are directed
  ll Ddfs(int x,ll flow)
  {
    if(!flow) return 0;if(x==t) return flow ;
    for(int &pt=Dptr[x];pt<sz(ad[x]);++pt)
      {
	int e=ad[x][pt];//call dinic()
      if(Dlevel[E[e].b]==Dlevel[x]+1)
	{
	  if(ll pushed=Ddfs(E[e].b,min(flow,E[e].c-E[e].f)))
	    {
	      E[e].f+=pushed;E[e^1].f-=pushed;return pushed;
	    }
	}
      }
    return 0 ;
  }
  ll dinic(void)
  {
    ll flow=0;
    while(Dbfs())
      {
	FEN(i,nodeCt)Dptr[i]=0;
	while(ll pushed=Ddfs(s,inf)) flow += pushed ;
      }
    return flow ;
  }
  void reset(void)
  {
    for(auto &e:E)e.f=0;
  }
};//!!!don't forget to set L
const int N=105,inf=1e9;
string s[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  flow f;
  int n,m;
  cin>>n>>m;
  ii ind1,ind2;
  rep(i,1,n+1) cin>>s[i],s[i]="#"+s[i];
  rep(i,1,n+1)
    rep(j,1,m+1)
    {
      if(s[i][j]=='S') ind1=mp(i,j);
      else if(s[i][j]=='T') ind2=mp(i,j);
    }
  f.nodeCt=n+m+2;
  f.s=n+m+1;
  f.t=n+m+2;
  rep(i,1,n+1)
    rep(j,1,m+1)
    if(s[i][j]=='o')
      f.addedge(i,n+j,1,false);
  f.addedge(f.s,ind1.fi,inf);
  f.addedge(f.s,n+ind1.se,inf);
  f.addedge(ind2.fi,f.t,inf);
  f.addedge(n+ind2.se,f.t,inf);
  int ans=f.dinic();
  if(ans>n*m) ans=-1;
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 1436