#include <bits/stdc++.h>
const int kInf = 0x3f3f3f3f;
const int kFx[4] = {-1, 1, 0, 0}, kFy[4] = {0, 0, -1, 1};
const int kMaxN = 1500, kMaxM = 1500;
int n, m;
char buf[kMaxN][kMaxM + 1];
int offset[kMaxN][kMaxM][2];
bool Dfs(int x, int y, int ox, int oy) {
  if (x < 0) return Dfs(n - 1, y, ox - 1, oy);
  if (x >= n) return Dfs(0, y, ox + 1, oy);
  if (y < 0) return Dfs(x, m - 1, ox, oy - 1);
  if (y >= m) return Dfs(x, 0, ox, oy + 1);
  if (buf[x][y] == '#') return false;
  if (offset[x][y][0] == ox && offset[x][y][1] == oy) return false;
  if (offset[x][y][0] != kInf) return true;
  offset[x][y][0] = ox;
  offset[x][y][1] = oy;
  for (int d = 0; d < 4; ++d)
    if (Dfs(x + kFx[d], y + kFy[d], ox, oy)) return true;
  return false;
}
int main() {
  int sx, sy;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf[i]);
    for (int j = 0; j < m; ++j)
      if (buf[i][j] == 'S') sx = i, sy = j;
  }
  memset(offset, 0x3f, sizeof(offset));
  if (Dfs(sx, sy, 0, 0))
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
