#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
queue<node> Q;
int n, m, sx, sy;
char s[3005][3005];
bool vis[3005][3005];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int main() {
  scanf("%d%d", &n, &m);
  gets(s[0]);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; ++i) {
    gets(s[i]);
    for (int j = 0; j < m; ++j)
      if (s[i][j] == 'S') {
        node a;
        a.x = sx = i;
        a.y = sy = j;
        Q.push(a);
        vis[i][j] = 1;
      }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) s[i][j + m] = s[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 2 * m; ++j) s[i + n][j] = s[i][j];
  while (!Q.empty()) {
    node a, b;
    a = Q.front();
    Q.pop();
    for (int i = 0; i < 4; ++i) {
      int x = a.x + dx[i];
      int y = a.y + dy[i];
      if (x < 0) x += 2 * n;
      if (y < 0) y += 2 * m;
      if (x >= 2 * n) x -= 2 * n;
      if (y >= 2 * m) y -= 2 * m;
      if ((x != sx || y != sy) && x % n == sx && y % m == sy) {
        printf("Yes\n");
        return 0;
      }
      if (!vis[x][y] && s[x][y] != '#') {
        b.x = x;
        b.y = y;
        vis[x][y] = 1;
        Q.push(b);
      }
    }
  }
  printf("No\n");
  return 0;
}
