#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510;
int n, m, sx, sy;
char s[maxn];
bool Map[maxn][maxn];
int dx[4] = {0, -1, 1, 0}, dy[4] = {1, 0, 0, -1};
int Dex[maxn][maxn], Dey[maxn][maxn];
bool DFS(int x, int y, int dex, int dey) {
  for (int i = 0; i < 4; ++i) {
    int X = (x + dx[i] + n) % n, Y = (y + dy[i] + m) % m;
    if (Map[X][Y]) continue;
    if ((Dex[X][Y] || Dey[X][Y]) || (X == sx && Y == sy)) {
      if (Dex[X][Y] != dex + dx[i] || Dey[X][Y] != dey + dy[i]) return 1;
      continue;
    }
    Dex[X][Y] = dex + dx[i];
    Dey[X][Y] = dey + dy[i];
    if (DFS(X, Y, dex + dx[i], dey + dy[i])) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < m; ++j)
      if (s[j] == 'S') {
        sx = i;
        sy = j;
      } else {
        if (s[j] == '#') Map[i][j] = 1;
      }
  }
  if (DFS(sx, sy, 0, 0))
    puts("Yes");
  else
    puts("No");
  return 0;
}
