#include <bits/stdc++.h>
using namespace std;
char grid[1505][1505];
char lgrid[1505 * 9][1505 * 9];
typedef struct pos {
  int r, c;
} pos;
queue<pos> myQ;
int offset[4][2] = {{-1, 0}, {0, 1}, {0, -1}, {1, 0}};
int N, M;
bool isValid(pos n) { return n.r >= 0 && n.r < N && n.c < M && n.c >= 0; }
int main() {
  pos start, cur, next;
  int n, m, i, j, k, p, q;
  int found, reached;
  while (scanf("%d %d", &n, &m) == 2) {
    memset(grid, 0, sizeof(grid));
    reached = found = 0;
    for (i = 0; i < n; i++) {
      scanf("%s", grid[i]);
      if (!found)
        for (j = 0; j < m; j++) {
          if (grid[i][j] == 'S') {
            start.r = i;
            start.c = j;
            found = 1;
          }
        }
    }
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 3; j++) {
        for (p = 0; p < n; p++) {
          for (q = 0; q < m; q++) {
            lgrid[i * n + p][j * m + q] = grid[p][q];
          }
        }
      }
    }
    start.r += n;
    start.c += m;
    N = n * 3;
    M = m * 3;
    lgrid[start.r][start.c] = '+';
    while (!myQ.empty()) myQ.pop();
    myQ.push(start);
    while (!myQ.empty() && !reached) {
      cur = myQ.front();
      myQ.pop();
      for (int k = 0; k < 4 && !reached; k++) {
        next.r = (cur.r + offset[k][0] + N) % N;
        next.c = (cur.c + offset[k][1] + M) % M;
        if (isValid(next) && !lgrid[next.r][next.c] != '+') {
          if (lgrid[next.r][next.c] == '.') {
            lgrid[next.r][next.c] = '+';
            myQ.push(next);
          } else if (lgrid[next.r][next.c] == 'S') {
            reached = 1;
            printf("Yes\n");
          }
        }
      }
    }
    if (!reached) {
      printf("No\n");
    }
  }
  return 0;
}
