#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
  int x, y;
};
int dirx[4] = {0, 0, -1, 1};
int diry[4] = {-1, 1, 0, 0};
int visx[1505][1505];
int visy[1505][1505];
char s[1505][1505];
queue<node> q;
int main() {
  int i, j, k, stx, sty;
  node now, next;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        stx = i;
        sty = j;
      }
      visx[i][j] = 10086111;
      visy[i][j] = 10086111;
    }
  }
  now.x = stx;
  now.y = sty;
  int tag = 0;
  visx[stx][sty] = stx;
  visy[stx][sty] = sty;
  q.push(now);
  int xx, yy;
  while (!q.empty()) {
    now = q.front();
    q.pop();
    for (i = 0; i < 4; i++) {
      next.x = now.x + dirx[i];
      next.y = now.y + diry[i];
      xx = (next.x % n + n) % n;
      yy = (next.y % m + m) % m;
      if (s[xx][yy] != '#') {
        if (visx[xx][yy] == 10086111) {
          visx[xx][yy] = next.x;
          visy[xx][yy] = next.y;
          q.push(next);
        } else if (visx[xx][yy] != next.x || visy[xx][yy] != next.y) {
          tag = 1;
          goto loop;
        }
      }
    }
  }
loop:;
  if (tag)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
