#include <bits/stdc++.h>
using namespace std;
char g[1600][1600];
int mark[1600][1600][2];
bool visit[1600][1600];
int dir[][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int n, m;
int s_x, s_y;
struct node {
  int x, y;
  int d_x, d_y;
};
bool bfs() {
  queue<node> Q;
  memset(mark, 0, sizeof(mark));
  memset(visit, 0, sizeof(visit));
  node N, P;
  N.x = s_x;
  N.y = s_y;
  N.d_x = 0;
  N.d_y = 0;
  Q.push(N);
  mark[N.x][N.y][0] = 0;
  mark[N.y][N.y][1] = 0;
  visit[N.x][N.y] = 1;
  while (!Q.empty()) {
    N = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      P.x = N.x + dir[i][0];
      P.y = N.y + dir[i][1];
      P.d_x = N.d_x;
      P.d_y = N.d_y;
      if (P.x < 0) {
        --P.d_x;
        P.x += n;
      }
      if (P.x >= n) {
        ++P.d_x;
        P.x -= n;
      }
      if (P.y < 0) {
        --P.d_y;
        P.y += m;
      }
      if (P.y >= m) {
        ++P.d_y;
        P.y -= m;
      }
      if (g[P.x][P.y] == '#') continue;
      if (visit[P.x][P.y]) {
        if (mark[P.x][P.y][0] != P.d_x || mark[P.x][P.y][1] != P.d_y)
          return true;
      } else {
        mark[P.x][P.y][0] = P.d_x;
        mark[P.x][P.y][1] = P.d_y;
        visit[P.x][P.y] = 1;
        Q.push(P);
      }
    }
  }
  return false;
}
int main() {
  int i, j, k;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      scanf("%s", &g[i]);
      for (int j = 0; j < m; j++) {
        if (g[i][j] == 'S') {
          g[i][j] = '.';
          s_x = i;
          s_y = j;
        }
      }
    }
    if (bfs())
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
