#include <bits/stdc++.h>
using namespace std;
int n, m;
char field[1500][1501];
int mov[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
struct Loc {
  int ty, tx, y, x;
  Loc(int _ty, int _tx, int _y, int _x) : ty(_ty), tx(_tx), y(_y), x(_x) {}
};
queue<Loc> q;
bool isVisit[1500][1500];
pair<int, int> flag[1500][1500];
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", field[i]);
  int sy, sx;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (field[i][j] == 'S') {
        sy = i;
        sx = j;
      }
  q.push(Loc(0, 0, sy, sx));
  isVisit[sy][sx] = true;
  flag[sy][sx] = make_pair(0, 0);
  bool isAns = false;
  while (!q.empty()) {
    int ty = q.front().ty;
    int tx = q.front().tx;
    int y = q.front().y;
    int x = q.front().x;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + mov[i][0];
      int nx = x + mov[i][1];
      if (ny >= 0 && ny < n && nx >= 0 && nx < m) {
        if (field[ny][nx] == '#') continue;
        if (!isVisit[ny][nx]) {
          isVisit[ny][nx] = true;
          flag[ny][nx] = make_pair(ty, tx);
          q.push(Loc(ty, tx, ny, nx));
        } else if (flag[ny][nx] != make_pair(ty, tx))
          isAns = true;
      } else if (ny == -1) {
        if (field[n - 1][nx] == '#') continue;
        if (!isVisit[n - 1][nx]) {
          isVisit[n - 1][nx] = true;
          flag[n - 1][nx] = make_pair(ty - 1, tx);
          q.push(Loc(ty - 1, tx, n - 1, nx));
        } else if (flag[n - 1][nx] != make_pair(ty - 1, tx))
          isAns = true;
      } else if (ny == n) {
        if (field[0][nx] == '#') continue;
        if (!isVisit[0][nx]) {
          isVisit[0][nx] = true;
          flag[0][nx] = make_pair(ty + 1, tx);
          q.push(Loc(ty + 1, tx, 0, nx));
        } else if (flag[0][nx] != make_pair(ty + 1, tx))
          isAns = true;
      } else if (nx == -1) {
        if (field[ny][m - 1] == '#') continue;
        if (!isVisit[ny][m - 1]) {
          isVisit[ny][m - 1] = true;
          flag[ny][m - 1] = make_pair(ty, tx - 1);
          q.push(Loc(ty, tx - 1, ny, m - 1));
        } else if (flag[ny][m - 1] != make_pair(ty, tx - 1))
          isAns = true;
      } else if (nx == m) {
        if (field[ny][0] == '#') continue;
        if (!isVisit[ny][0]) {
          isVisit[ny][0] = true;
          flag[ny][0] = make_pair(ty, tx + 1);
          q.push(Loc(ty, tx + 1, ny, 0));
        } else if (flag[ny][0] != make_pair(ty, tx + 1))
          isAns = true;
      }
    }
    if (isAns) break;
  }
  if (isAns)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
