#include <bits/stdc++.h>
using namespace std;
const int N = 1600;
const int IMP = 0x7f7f7f7f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
int n, m, sx, sy;
string g[N];
int vx[N][N], vy[N][N], top;
pair<int, int> q[N * N];
bool dfs() {
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) vx[i][j] = vy[i][j] = IMP;
  vx[sx][sy] = sx, vy[sx][sy] = sy;
  q[top = 1] = make_pair(sx, sy);
  while (top > 0) {
    int x = q[top].first;
    int y = q[top--].second;
    for (int d = 0; d < (4); d++) {
      int nx = x + dx[d], ox = (nx % n + n) % n;
      int ny = y + dy[d], oy = (ny % m + m) % m;
      if (g[ox][oy] == '#') continue;
      if (vx[ox][oy] == IMP) {
        vx[ox][oy] = nx, vy[ox][oy] = ny;
        q[++top] = make_pair(nx, ny);
      } else if (vx[ox][oy] != nx || vy[ox][oy] != ny)
        return true;
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (n); i++) {
    cin >> g[i];
    for (int j = 0; j < (m); j++)
      if (g[i][j] == 'S') sx = i, sy = j;
  }
  if (dfs())
    puts("Yes");
  else
    puts("No");
  return 0;
}
