#include <bits/stdc++.h>
using namespace std;
char ch[1510][1510];
int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};
int xx, yy;
int n, m;
int fla;
struct inst {
  int x;
  int y;
  inst() {}
  inst(int x, int y) : x(x), y(y) {}
};
inst vis[1510][1510];
void bfs() {
  queue<inst> q;
  q.push(inst(xx, yy));
  vis[xx][yy].x = xx;
  vis[xx][yy].y = yy;
  while (!q.empty()) {
    inst nd = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x1 = nd.x + dx[i];
      int y1 = nd.y + dy[i];
      int x2 = x1 % n;
      int y2 = y1 % m;
      if (x2 < 0) x2 += n;
      if (y2 < 0) y2 += m;
      if (vis[x2][y2].x == -0x3f3f3f3f && vis[x2][y2].y == -0x3f3f3f3f &&
          ch[x2][y2] != '#') {
        vis[x2][y2].x = x1;
        vis[x2][y2].y = y1;
        q.push(inst(x1, y1));
      } else if ((vis[x2][y2].x != x1 || vis[x2][y2].y != y1) &&
                 ch[x2][y2] != '#' &&
                 (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m)) {
        fla = 1;
        return;
      }
    }
  }
  return;
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) {
    for (int z = 0; z <= m; z++) {
      vis[i][z].x = vis[i][z].y = -0x3f3f3f3f;
    }
  }
  fla = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", ch[i]);
    for (int z = 0; z < m; z++) {
      if (ch[i][z] == 'S') {
        xx = i;
        yy = z;
      }
    }
  }
  bfs();
  if (fla) {
    printf("Yes\n");
  } else
    printf("No\n");
}
