#include <bits/stdc++.h>
using namespace std;
const int N = 1510, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, m, sx, sy, vis[N][N], wx[N][N], wy[N][N], mp[N][N];
char s[N];
inline bool dfs(int x, int y) {
  int u = ((x - 1) % n + n) % n + 1, v = ((y - 1) % m + m) % m + 1;
  if (mp[u][v]) return 0;
  if (vis[u][v]) return wx[u][v] != x || wy[u][v] != y;
  vis[u][v] = 1;
  wx[u][v] = x;
  wy[u][v] = y;
  for (int i = 0; i < 4; ++i)
    if (dfs(x + dx[i], y + dy[i])) return 1;
  return 0;
}
int main() {
  while (scanf("%d%d", &n, &m) > 0) {
    for (int i = 1; i <= n; ++i) {
      scanf("%s", s + 1);
      for (int j = 1; j <= m; ++j) {
        if (s[j] == 'S') sx = i, sy = j;
        mp[i][j] = (s[j] == '#');
        wx[i][j] = wy[i][j] = vis[i][j] = 0;
      }
    }
    puts(dfs(sx, sy) ? "Yes" : "No");
  }
  return 0;
}
