#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, dx, dy;
} now;
int n, m, sx, sy, top, tmp;
int dir[4][2];
char mp[1510][1510];
pair<int, int> vis[1510][1510];
queue<node> Q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", mp[i]);
    for (int j = 0; j < m; j++) {
      if (mp[i][j] == 'S') sx = i, sy = j, mp[i][j] = '.';
      vis[i][j].first = vis[i][j].second = 2000;
    }
  }
  m--, n--;
  dir[0][0] = dir[1][1] = dir[2][0] = dir[3][1] = 0;
  dir[0][1] = dir[3][0] = 1;
  dir[1][0] = dir[2][1] = -1;
  int tot = 0;
  Q.push((node){sx, sy, 0, 0});
  while (!Q.empty()) {
    now = Q.front();
    Q.pop();
    for (int i = 0; i <= 3; i++) {
      int x = now.x + dir[i][0], y = now.y + dir[i][1], dx = now.dx,
          dy = now.dy;
      if (x < 0 && mp[n][y] == '.') dx--, x = n;
      if (x > n && mp[0][y] == '.') dx++, x = 0;
      if (y < 0 && mp[x][m] == '.') dy--, y = m;
      if (y > m && mp[x][0] == '.') dy++, y = 0;
      if (mp[x][y] != '.') continue;
      if (vis[x][y].first == 2000) {
        Q.push((node){x, y, dx, dy});
        vis[x][y].first = dx;
        vis[x][y].second = dy;
      } else if (vis[x][y].first != dx || vis[x][y].second != dy) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}
