#include <bits/stdc++.h>
using namespace std;
int n, m, savx, savy, tag = 1;
char maze[1510][1510];
int vis[1510][1510][2] = {0};
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
bool solve(int x, int y, int ex, int ey) {
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    int cx = ex, cy = ey;
    if (nx >= n) cx--;
    if (nx < 0) cx++;
    if (ny >= m) cy--;
    if (ny < 0) cy++;
    int a = (nx + n) % n, b = (ny + m) % m;
    if (maze[a][b] == '#') continue;
    if (vis[a][b][0]) {
      if (vis[a][b][0] != cx || vis[a][b][1] != cy) return 1;
      continue;
    }
    vis[a][b][0] = cx;
    vis[a][b][1] = cy;
    if (solve(a, b, cx, cy)) return 1;
  }
  return 0;
}
int main() {
  int i, j;
  scanf("%d %d", &n, &m);
  getchar();
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%c", &maze[i][j]);
      if (maze[i][j] == 'S') {
        savx = i;
        savy = j;
      }
    }
    getchar();
  }
  memset(vis, 0, sizeof(vis));
  if (solve(savx, savy, 0xffffff, 0xffffff))
    puts("Yes");
  else
    puts("No");
  return 0;
}
