#include <bits/stdc++.h>
#define left lolkek
using namespace std;
int n, m;
vector<int> dx = {-1, 1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
vector<char> dir = {'L', 'R', 'U', 'D'};
vector<vector<int>> grid;
vector<vector<int>> left;
vector<vector<int>> up;
int si = 0;
int sj = 0;
int ti = 0;
int tj = 0;
string path;
void dfs(int i, int j, int d, int t) {
path += dir[d];
if (t > 1 || i < 1 || i > n || j < 1 || j > m || grid[i][j] == 1) {
path.pop_back();
return;
}
if (j == tj) {
int occ = up[max(ti, i)][j] - up[min(ti, i) - 1][j];
if (occ == 0) {
cout << "YES";
exit(0);
}
} else if (i == ti) {
int occ = left[i][max(tj, j)] - left[i][min(tj, j) - 1];
if (occ == 0) {
cout << "YES";
exit(0);
}
}
for (int d1 = 0; d1 < 4; d1++) {
if (d1 == d || d1 == (d ^ 1)) continue;
dfs(i + dy[d1], j + dx[d1], d1, t + 1);
}
dfs(i + dy[d], j + dx[d], d, t);
path.pop_back();
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
grid.assign(n + 1, vector<int>(m + 1, 0));
string inp;
for (int i = 0; i < n; i++) {
cin >> inp;
for (int j = 0; j < m; j++) {
if (inp[j] == '*') {
grid[i + 1][j + 1] = 1;
}
if (inp[j] == 'S') {
si = i + 1;
sj = j + 1;
} else if (inp[j] == 'T') {
ti = i + 1;
tj = j + 1;
}
}
}
left.assign(n + 1, vector<int>(m + 1, 0));
up.assign(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
left[i][j] = left[i][j - 1] + grid[i][j];
up[i][j] = up[i - 1][j] + grid[i][j];
}
}
for (int d = 0; d < 4; d++) {
dfs(si + dy[d], sj + dx[d], d, 0);
}
cout << "NO";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGVmdCBsb2xrZWsKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCm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AoZCBeIDEpKSBjb250aW51ZTsKICAgICAgICBkZnMoaSArIGR5W2QxXSwgaiArIGR4W2QxXSwgZDEsIHQgKyAxKTsKICAgIH0KICAgIGRmcyhpICsgZHlbZF0sIGogKyBkeFtkXSwgZCwgdCk7CiAgICBwYXRoLnBvcF9iYWNrKCk7Cn0KIAppbnQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwogICAgY2luID4+IG4gPj4gbTsKICAgIGdyaWQuYXNzaWduKG4gKyAxLCB2ZWN0b3I8aW50PihtICsgMSwgMCkpOwogICAgc3RyaW5nIGlucDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGlucDsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IG07IGorKykgewogICAgICAgICAgICBpZiAoaW5wW2pdID09ICcqJykgewogICAgICAgICAgICAgICAgZ3JpZFtpICsgMV1baiArIDFdID0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoaW5wW2pdID09ICdTJykgewogICAgICAgICAgICAgICAgc2kgPSBpICsgMTsKICAgICAgICAgICAgICAgIHNqID0gaiArIDE7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaW5wW2pdID09ICdUJykgewogICAgICAgICAgICAgICAgdGkgPSBpICsgMTsKICAgICAgICAgICAgICAgIHRqID0gaiArIDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBsZWZ0LmFzc2lnbihuICsgMSwgdmVjdG9yPGludD4obSArIDEsIDApKTsKICAgIHVwLmFzc2lnbihuICsgMSwgdmVjdG9yPGludD4obSArIDEsIDApKTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG07IGorKykgewogICAgICAgICAgICBsZWZ0W2ldW2pdID0gbGVmdFtpXVtqIC0gMV0gKyBncmlkW2ldW2pdOwogICAgICAgICAgICB1cFtpXVtqXSA9IHVwW2kgLSAxXVtqXSArIGdyaWRbaV1bal07CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgZCA9IDA7IGQgPCA0OyBkKyspIHsKICAgICAgICBkZnMoc2kgKyBkeVtkXSwgc2ogKyBkeFtkXSwgZCwgMCk7CiAgICB9CiAgICBjb3V0IDw8ICJOTyI7Cn0KIA==