#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int d[1001][1001];
int used[1001][1001][2];
int n, k;
int foo(int x, int y, int f, int dir) {
  if (f == -1 || x == -1 || x == n || y == -1 || y == k || d[x][y] == 1 ||
      used[x][y][dir]) {
    return 0;
  }
  if (d[x][y] == 2) {
    return 1;
  }
  used[x][y][dir] = 1;
  int res = 0;
  if (dir) {
    res = res || foo(x - 1, y, f, dir);
    res = res || foo(x + 1, y, f, dir);
    res = res || foo(x, y - 1, f - 1, !dir);
    res = res || foo(x, y + 1, f - 1, !dir);
  } else {
    res = res || foo(x, y - 1, f, dir);
    res = res || foo(x, y + 1, f, dir);
    res = res || foo(x - 1, y, f - 1, !dir);
    res = res || foo(x + 1, y, f - 1, !dir);
  }
  return res;
}
int main() {
  scanf("%d%d ", &n, &k);
  char c;
  int stx = -1, sty = -1, fx = -1, fy = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      scanf("%c", &c);
      if (c == '.') {
        continue;
      }
      if (c == '*') {
        d[i][j] = 1;
        continue;
      }
      if (c == 'S') {
        stx = i, sty = j;
        continue;
      }
      d[i][j] = 2;
      fx = i, fy = j;
    }
    scanf("%c", &c);
  }
  int res = foo(stx, sty, 2, 1);
  if (!res) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < k; ++j) {
        used[i][j][0] = 0;
        used[i][j][1] = 0;
      }
    }
    res = foo(stx, sty, 2, 0);
  }
  if (res) {
    printf("YES");
  } else {
    printf("NO");
  }
  return 0;
}
