#include <bits/stdc++.h>
int n, m, sx, sy;
bool map[1505][1505] = {0}, vis[1505][1505] = {0};
int fir[2][1505][1505];
bool dfs(int x, int y) {
  int cx = (x % n + n) % n, cy = (y % m + m) % m;
  if (map[cx][cy] == 1) return false;
  if (vis[cx][cy])
    if (x != fir[0][cx][cy] || y != fir[1][cx][cy])
      return true;
    else
      return false;
  vis[cx][cy] = 1;
  fir[0][cx][cy] = x;
  fir[1][cx][cy] = y;
  if (dfs(x + 1, y)) return true;
  if (dfs(x, y + 1)) return true;
  if (dfs(x - 1, y)) return true;
  if (dfs(x, y - 1)) return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  int i, j;
  char temp;
  for (i = 0; i < n; i++) {
    getchar();
    for (j = 0; j < m; j++) {
      scanf("%c", &temp);
      if (temp == '#') map[i][j] = 1;
      if (temp == 'S') {
        sx = i;
        sy = j;
      }
    }
  }
  if (dfs(sx, sy))
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
