#include <bits/stdc++.h>
using namespace std;
const int N = 1555;
struct point {
  int x, y, col;
  point(int x = 0, int y = 0, int col = 0) : x(x), y(y), col(col) {}
} que[N * N];
int n, m;
char mat[N][N];
int vis[N][N];
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void go(int &x, int &y, int &col) {
  if (x < 0) x += n, col += 7;
  if (x >= n) x -= n, col -= 7;
  if (y < 0) y += m, col += 10007;
  if (y >= m) y -= m, col -= 10007;
}
bool work(int bx, int by) {
  int qf, qe;
  qf = 0;
  qe = -1;
  vis[bx][by] = 1;
  que[++qe] = point(bx, by, 1);
  while (qf <= qe) {
    point f = que[qf++];
    for (int i = 0; i < 4; i++) {
      point e = f;
      go(e.x += dir[i][0], e.y += dir[i][1], e.col);
      if (mat[e.x][e.y] == '#') continue;
      if (e.col == vis[e.x][e.y]) continue;
      if (vis[e.x][e.y] != 0) return true;
      vis[e.x][e.y] = e.col;
      que[++qe] = e;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  int bx, by;
  for (int i = 0; i < n; i++) {
    scanf("%s", mat[i]);
    for (int j = 0; j < m; j++)
      if (mat[i][j] == 'S') bx = i, by = j;
  }
  puts(work(bx, by) ? "Yes" : "No");
  return 0;
}
