#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
struct pt {
  int x, y;
} f[1510][1510];
int n, m, v[1510][1510];
char p[1510][1510];
bool dfs(int x, int y) {
  int A = (x % n + n) % n, B = (y % m + m) % m;
  if (p[A][B] == '#') return 0;
  if (v[A][B]) return f[A][B].x != x || f[A][B].y != y;
  v[A][B] = 1;
  f[A][B] = (pt){x, y};
  for (int i = 0; i <= 3; i++)
    if (dfs(x + dx[i], y + dy[i])) return 1;
  return 0;
}
int main() {
  memset(v, 0, sizeof(v));
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n - 1; i++) scanf("%s", p[i]);
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++)
      if (p[i][j] == 'S') {
        p[i][j] = '.';
        printf("%s\n", dfs(i, j) ? "Yes" : "No");
        return 0;
      }
}
