#include <bits/stdc++.h>
const int xy[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int n, m, sx, sy, vx[1501][1501], vy[1501][1501];
bool map[1501][1501], visited[1501][1501];
void dfs(int x, int y, const int rx, const int ry) {
  if (x == 0) x = n;
  if (x == n + 1) x = 1;
  if (y == 0) y = m;
  if (y == m + 1) y = 1;
  if (map[x][y]) return;
  if (visited[x][y]) {
    if (vx[x][y] != rx || vy[x][y] != ry) {
      printf("Yes");
      exit(0);
    }
    return;
  }
  visited[x][y] = true;
  vx[x][y] = rx, vy[x][y] = ry;
  for (int i = 0; i < 4; ++i)
    dfs(x + xy[i][0], y + xy[i][1], rx + xy[i][0], ry + xy[i][1]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("\n");
    for (int j = 1; j <= m; ++j) {
      char c;
      scanf("%c", &c);
      if (c == 'S') sx = i, sy = j;
      if (c == '#') map[i][j] = true;
    }
  }
  dfs(sx, sy, sx, sy);
  printf("No");
}
