#include <bits/stdc++.h>
using namespace std;
const int maxn = 1502;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
struct State {
  int x, y;
  State(int _, int __) : x(_), y(__) {}
};
int n, m, mx[maxn][maxn], my[maxn][maxn];
bool used[maxn][maxn];
queue<State> qq;
char brd[maxn][maxn];
bool valid(int x, int y, int& hhx, int& hhy) {
  int px = (x % n + n) % n;
  int py = (y % m + m) % m;
  if (brd[px][py] != '.') return false;
  hhx = x / n, hhy = y / m;
  if (x < 0) hhx--;
  if (y < 0) hhy--;
  if (used[px][py] && mx[px][py] == hhx && my[px][py] == hhy) return false;
  return true;
}
bool bfs() {
  int sx, sy;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (brd[i][j] == 'S') {
        sx = i;
        sy = j;
        brd[i][j] = '.';
      }
  qq.push(State(sx, sy));
  memset(used, 0, sizeof(used));
  used[sx][sy] = true;
  mx[sx][sy] = 0;
  my[sx][sy] = 0;
  while (!qq.empty()) {
    State ss = qq.front();
    qq.pop();
    for (int i = 0; i < 4; i++) {
      int nx = ss.x + dx[i], ny = ss.y + dy[i];
      int hhx, hhy;
      if (valid(nx, ny, hhx, hhy)) {
        int px = (nx % n + n) % n;
        int py = (ny % m + m) % m;
        if (used[px][py])
          return true;
        else {
          used[px][py] = true;
          mx[px][py] = hhx;
          my[px][py] = hhy;
        }
        qq.push(State(nx, ny));
      }
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", brd[i]);
  if (bfs())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
