#include <bits/stdc++.h>
using namespace std;
const int NN = 1505;
bool vis[NN][NN];
int rex[NN][NN], rey[NN][NN];
char mat[NN][NN];
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
struct node {
  int x, y;
  node() {}
  node(int a, int b) {
    x = a;
    y = b;
  }
};
bool bfs(int n, int m, int stx, int sty) {
  memset(vis, false, sizeof(vis));
  vis[stx][sty] = true;
  rex[stx][sty] = stx;
  rey[stx][sty] = sty;
  node kk(stx, sty);
  queue<node> q;
  q.push(kk);
  int i, xx, yy, tx, ty;
  while (!q.empty()) {
    kk = q.front();
    q.pop();
    for (i = 0; i < 4; i++) {
      xx = kk.x + dir[i][0];
      yy = kk.y + dir[i][1];
      tx = xx;
      while (tx < 0) tx += n;
      tx = tx % n;
      ty = yy;
      while (ty < 0) ty += m;
      ty = ty % m;
      if (mat[tx][ty] != '#') {
        if (!vis[tx][ty]) {
          vis[tx][ty] = true;
          rex[tx][ty] = xx;
          rey[tx][ty] = yy;
          q.push(node(xx, yy));
        } else {
          if (xx != rex[tx][ty] || yy != rey[tx][ty]) return true;
        }
      }
    }
  }
  return false;
}
int main() {
  int n, m, stx, sty;
  int i, j;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%s", mat[i]);
      for (j = 0; j < m; j++) {
        if (mat[i][j] == 'S') {
          stx = i;
          sty = j;
        }
      }
    }
    if (bfs(n, m, stx, sty))
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
