#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void PLAY() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout << fixed << setprecision(10);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n, m;
char a[1005][1005];
bool vis[1005][1005];
bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
int main() {
PLAY();
cin >> n >> m;
pair<int, int> start, end;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
if (a[i][j] == 'S') start = { i, j };
else if (a[i][j] == 'T') end = { i, j };
}
}
queue<pair<pair<int, int>, pair<int,int>>> qu;
qu.push({ start, { -1, 0 } });
while (sz(qu)) {
int x = qu.front().first.first;
int y = qu.front().first.second;
int lastmove = qu.front().second.first;
int cnt = qu.front().second.second;
qu.pop();
if (make_pair(x, y) == end) {
cout << "YES" << endl;
return 0;
}
if (vis[x][y]) continue;
vis[x][y] = true;
for (int i = 0; i < 4; i++) {
int tox = dx[i] + x;
int toy = dy[i] + y;
if (!valid(tox, toy)) continue;
if (a[tox][toy] == '*') continue;
if (lastmove == -1) {
if (!vis[tox][toy])
qu.push({ { tox, toy }, { i, 0 } });
}
else {
int newcnt = cnt + bool(lastmove != i);
if (newcnt > 2) continue;
if (!vis[tox][toy])
qu.push({ { tox, toy }, { i, newcnt } });
}
}
}
cout << "NO" << endl;
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxudW1lcmljPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxoYXNoX21hcD4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbGltaXRzPgojaW5jbH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