#include <bits/stdc++.h>
using namespace std;
const int N = 1515;
const int INF = 1e9;
int n, m;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int vis[N][N];
char Maze[N][N];
int getIndex(int x, int y) { return x * n + y; }
bool isValid(int x, int y) {
  return Maze[(x % n + n) % n][(y % m + m) % m] == '.';
}
bool DFS(int x, int y) {
  int curX = (x % n + n) % n;
  int curY = (y % m + m) % m;
  if (vis[curX][curY] != INF) {
    return vis[curX][curY] != getIndex(x, y);
  }
  vis[curX][curY] = getIndex(x, y);
  bool Res = false;
  for (int i = 0; i < 4; i++) {
    if (isValid(x + dx[i], y + dy[i])) Res |= DFS(x + dx[i], y + dy[i]);
  }
  return Res;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf(" %c", &Maze[i][j]);
      if (Maze[i][j] == 'S') {
        x = i;
        y = j;
        Maze[i][j] = '.';
      }
      vis[i][j] = INF;
    }
  DFS(x, y) ? puts("Yes") : puts("No");
  return 0;
}
