#include <bits/stdc++.h>
using namespace std;
const int N = 1555;
const int INF = 0x3f3f3f3f;
int sx, sy;
int n, m;
char maze[N][N];
int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1};
struct node {
  int x, y;
} vis[N][N];
bool bfs(int x, int y) {
  queue<node> q;
  node now, next;
  now.x = x;
  now.y = y;
  q.push(now);
  while (!q.empty()) {
    now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      next.x = now.x + dir[i][0];
      next.y = now.y + dir[i][1];
      if (maze[(next.x % n + n) % n][(next.y % m + m) % m] != '#') {
        if (vis[(next.x % n + n) % n][(next.y % m + m) % m].x == INF) {
          vis[(next.x % n + n) % n][(next.y % m + m) % m].x = next.x;
          vis[(next.x % n + n) % n][(next.y % m + m) % m].y = next.y;
          q.push(next);
        } else if (next.x !=
                       vis[(next.x % n + n) % n][(next.y % m + m) % m].x ||
                   next.y != vis[(next.x % n + n) % n][(next.y % m + m) % m].y)
          return true;
      }
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  memset(vis, INF, sizeof(vis));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == 'S') sx = i, sy = j;
    }
  }
  if (bfs(sx, sy))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
