#include <bits/stdc++.h>
using namespace std;
const int N(1510), Q(4 * N);
const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
struct TNode {
  int v, w;
  TNode *nxt;
};
TNode *g[Q];
int n, m, tot, sx, sy;
char s[N][N];
int qx[N * N], qy[N * N];
int q[Q], d[Q], ti[Q];
bool bo[Q];
int num[N][N];
void add(int u, int v, int w) {
  TNode *p = new TNode;
  p->v = v;
  p->w = w;
  p->nxt = g[u];
  g[u] = p;
  p = new TNode;
  p->v = u;
  p->w = -w;
  p->nxt = g[v];
  g[v] = p;
}
void bfs(int x, int y) {
  int t = 0;
  if (s[x][y] == '#') return;
  qx[t] = x;
  qy[t++] = y;
  num[x][y] = ++tot;
  for (int h = int(0); h < int(t); ++h)
    for (int i = int(0); i < int(4); ++i) {
      int tx = qx[h] + dir[i][0], ty = qy[h] + dir[i][1];
      if (tx == -1 || ty == -1 || tx == n || ty == m || num[tx][ty] ||
          s[tx][ty] == '#')
        continue;
      num[tx][ty] = tot;
      qx[t] = tx;
      qy[t++] = ty;
    }
}
int nxt(int x) { return (x + 1) % Q; }
bool spfa() {
  int h, t(0);
  memset(bo, 0, sizeof(bo));
  ;
  memset(ti, 0, sizeof(ti));
  ;
  for (int i = int(1); i < int(tot + 1); ++i) d[i] = 30000;
  q[t++] = num[sx][sy];
  d[q[t - 1]] = 0;
  for (h = 0; h != t; h = nxt(h)) {
    for (TNode *p = g[q[h]]; p; p = p->nxt)
      if (d[q[h]] + p->w < d[p->v]) {
        if (q[h] == p->v) return true;
        d[p->v] = d[q[h]] + p->w;
        ti[p->v] = max(ti[p->v] + 1, ti[q[h]]);
        if (ti[p->v] > tot + 10) return true;
        if (!bo[p->v]) {
          bo[p->v] = true;
          q[t] = p->v;
          t = nxt(t);
        }
      }
    bo[q[h]] = false;
  }
  return false;
}
bool check(int dx, int dy) {
  memset(g, 0, sizeof(g));
  ;
  for (int i = int(0); i < int(n); ++i)
    if (s[i][0] != '#' && s[i][m - 1] != '#') add(num[i][0], num[i][m - 1], dx);
  for (int i = int(0); i < int(m); ++i)
    if (s[0][i] != '#' && s[n - 1][i] != '#') add(num[0][i], num[n - 1][i], dy);
  return spfa();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = int(0); i < int(n); ++i) {
    scanf("%s", s[i]);
    for (int j = int(0); j < int(m); ++j)
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      }
  }
  for (int i = int(0); i < int(n); ++i)
    if (!num[i][0]) bfs(i, 0);
  for (int i = int(0); i < int(n); ++i)
    if (!num[i][m - 1]) bfs(i, m - 1);
  for (int i = int(0); i < int(m); ++i)
    if (!num[0][i]) bfs(0, i);
  for (int i = int(0); i < int(m); ++i)
    if (!num[n - 1][i]) bfs(n - 1, i);
  if (num[sx][sy] == 0) {
    printf("No\n");
    return 0;
  }
  if (check(1, 0) || check(0, 1) || check(-1, 0) || check(0, -1)) {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}
