#include <bits/stdc++.h>
using namespace std;
const int INF = 1000111222;
const double eps = 1e-8;
const int NN = 1510;
const int MM = 1000010;
char mat[NN][NN];
bool vis[NN][NN];
int rex[NN][NN];
int rey[NN][NN];
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
struct node {
  int x, y;
};
void solve(int n, int m, int stx, int sty) {
  memset(vis, false, sizeof(vis));
  queue<node> q;
  node kk = {stx, sty};
  int i, tx, ty, realx, realy;
  rex[stx][sty] = stx;
  rey[stx][sty] = sty;
  vis[stx][sty] = true;
  q.push(kk);
  while (!q.empty()) {
    kk = q.front();
    q.pop();
    for (i = 0; i < 4; i++) {
      realx = kk.x + dir[i][0];
      realy = kk.y + dir[i][1];
      tx = (realx % n + n) % n;
      ty = (realy % m + m) % m;
      if (mat[tx][ty] == '#') continue;
      if (!vis[tx][ty]) {
        vis[tx][ty] = true;
        rex[tx][ty] = realx;
        rey[tx][ty] = realy;
        node tt = {realx, realy};
        q.push(tt);
      } else {
        if (realx != rex[tx][ty] || realy != rey[tx][ty]) {
          puts("Yes");
          return;
        }
      }
    }
  }
  puts("No");
}
int main() {
  int n, m, i, j, stx, sty;
  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;
        }
      }
    }
    solve(n, m, stx, sty);
  }
  return 0;
}
