#include <bits/stdc++.h>
using namespace std;
int n, m, dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}, sx, sy, xx, yy, nx, ny,
          xa[1505][1505], ya[1505][1505];
bool vis[1505][1505];
char in[1505][1505];
bool dfs(int x, int y) {
  vis[((x % n) + n) % n][((y % m) + m) % m] = true;
  for (int i = 0; i <= 3; i++) {
    xx = x + dx[i];
    yy = y + dy[i];
    nx = ((xx % n) + n) % n;
    ny = ((yy % m) + m) % m;
    if (vis[nx][ny]) {
      if (xa[nx][ny] != xx || ya[nx][ny] != yy) return true;
    } else if (in[nx][ny] == '.') {
      xa[nx][ny] = xx;
      ya[nx][ny] = yy;
      if (dfs(xx, yy)) return true;
    }
  }
  return false;
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    memset(vis, false, sizeof(vis));
    for (int i = 0; i <= n - 1; i++) {
      scanf("%s", in[i]);
      for (int j = 0; j <= m - 1; j++)
        if (in[i][j] == 'S') {
          sx = i;
          sy = j;
          in[i][j] = '.';
        }
    }
    xa[sx][sy] = sx;
    ya[sx][sy] = sy;
    if (dfs(sx, sy))
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}
