#include <bits/stdc++.h>
using namespace std;
char g[2000][2000];
int fa[3000010];
bool fg[3000010], boo2[3000010];
int fg2[30000010];
bool boo[2000][2000];
int n, m, sx, sy;
int mmm;
const int di[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void dfs(int x, int y, int fat) {
  boo[x][y] = true;
  int tmp = (x - 1) * m + y;
  fa[tmp] = fat;
  for (int i = 0; i < 4; i++) {
    int x1, y1;
    x1 = x + di[i][0];
    y1 = y + di[i][1];
    if (x1 > 0 && x1 <= n && y1 > 0 && y1 <= m && !boo[x1][y1] &&
        g[x1][y1] != '#')
      dfs(x1, y1, fat);
  }
}
bool dfs2(int x, int y, int now) {
  boo[x][y] = true;
  int tmp = (x - 1) * m + y;
  fg2[fa[tmp]] = now;
  for (int i = 0; i < 4; i++) {
    int x1, y1;
    x1 = x + di[i][0];
    y1 = y + di[i][1];
    int tnow = now;
    if (x1 == 0) {
      x1 = n;
      tnow -= 2500;
    }
    if (y1 == 0) {
      y1 = m;
      tnow -= 1;
    }
    if (x1 == n + 1) {
      x1 = 1;
      tnow += 2500;
    }
    if (y1 == m + 1) {
      y1 = 1;
      tnow += 1;
    }
    if (boo[x1][y1] && fg2[fa[(x1 - 1) * m + y1]] != tnow) return true;
    if (!boo[x1][y1] && g[x1][y1] != '#') {
      if (dfs2(x1, y1, tnow)) return true;
    }
  }
  return false;
}
int father(int i) {
  if (fa[i] == i) return i;
  return fa[i] = father(fa[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  memset(boo, 0, sizeof(boo));
  for (int i = 0; i <= n * m + 1; i++) fa[i] = i;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &g[i][j]);
      if (g[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  dfs(sx, sy, (sx - 1) * m + sy);
  mmm = (sx - 1) * m + sy;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (!boo[i][j] && g[i][j] == '.') dfs(i, j, (i - 1) * m + j);
  memset(fg, 0, sizeof(fg));
  {
    for (int i = 1; i <= n; i++) {
      if (g[i][1] == '.' && g[i][m] == '.') {
        int tmp1 = (i - 1) * m + 1;
        int tmp2 = (i - 1) * m + m;
        if (fa[tmp1] == fa[tmp2]) fg[fa[tmp1]] = true;
      }
    }
    for (int j = 1; j <= m; j++) {
      if (g[1][j] == '.' && g[n][j] == '.') {
        int tmp1 = (n - 1) * 0 + j;
        int tmp2 = (n - 1) * m + j;
        if (fa[tmp1] == fa[tmp2]) fg[fa[tmp1]] = true;
      }
    }
  }
  memset(boo, 0, sizeof(boo));
  memset(boo2, 0, sizeof(boo2));
  for (int i = 0; i <= 3000000; i++) fg2[i] = 2000000000;
  if (dfs2(sx, sy, 0))
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
