#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
char mp[1550][1550];
int vis[1550][1550][2];
int sx, sy, n, m;
struct po {
  int x, y;
};
bool bfs() {
  po an = {sx, sy};
  vis[sx][sy][0] = sx;
  vis[sx][sy][1] = sy;
  queue<po> q;
  q.push(an);
  while (!q.empty()) {
    po v = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int xn = v.x + dx[i];
      int yn = v.y + dy[i];
      int xx = ((xn + n) % n + n) % n;
      int yy = ((yn + m) % m + m) % m;
      if (mp[xx][yy] == '#') continue;
      if (vis[xx][yy][0] == 0x3f3f3f3f) {
        vis[xx][yy][0] = xn;
        vis[xx][yy][1] = yn;
        po u = {xn, yn};
        q.push(u);
      } else {
        if (vis[xx][yy][0] != xn || vis[xx][yy][1] != yn)
          return true;
        else
          continue;
      }
    }
  }
  return false;
}
int main() {
  memset(vis, 0x3f, sizeof(vis));
  scanf("%d%d", &n, &m);
  getchar();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &mp[i][j]);
      if (mp[i][j] == 'S') {
        sx = i;
        sy = j;
        mp[i][j] = '.';
      }
    }
    getchar();
  }
  if (bfs())
    printf("Yes\n");
  else
    printf("No\n");
}
