#include <bits/stdc++.h>
using namespace std;
char s[1505][1505];
int r[1505][1505], tp = 0, tag, n, m;
int vis[1505][1505][2];
void dfs(int x, int y, int xd, int yd) {
  if (tag) return;
  if (xd < 0) xd += n;
  if (xd >= n) xd -= n;
  if (yd < 0) yd += m;
  if (yd >= m) yd -= m;
  if (s[xd][yd] == '#') return;
  if (r[xd][yd] == tp) {
    if (vis[xd][yd][0] != x || vis[xd][yd][1] != y) tag = 1;
    return;
  }
  r[xd][yd] = tp;
  vis[xd][yd][0] = x;
  vis[xd][yd][1] = y;
  dfs(x + 1, y, xd + 1, yd);
  dfs(x, y + 1, xd, yd + 1);
  dfs(x - 1, y, xd - 1, yd);
  dfs(x, y - 1, xd, yd - 1);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    int i, j, x = -1, y = -1;
    tp++;
    tag = 0;
    for (i = 0; i < n; i++) {
      scanf("%s", s[i]);
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (s[i][j] == 'S') {
          x = i;
          y = j;
          break;
        }
      }
      if (x >= 0) {
        break;
      }
    }
    dfs(x, y, x, y);
    puts(tag ? "Yes" : "No");
  }
  return 0;
}
