#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
char G[maxn][maxn];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool vis[maxn][maxn];
int x[5000010], y[5000010], n, m;
long long qx[1510][1510], qy[1510][1510];
int dir;
bool flg = false;
int main() {
  while (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') x[0] = i, y[0] = j;
      }
    }
    int rear = 0, front = 0;
    memset(vis, false, sizeof(vis));
    memset(qx, 0, sizeof(qx));
    memset(qy, 0, sizeof(qy));
    vis[x[0]][y[0]] = true;
    while (front <= rear) {
      for (int d = 0; d < 4; ++d) {
        int xk = x[front] + dx[d];
        int yk = y[front] + dy[d];
        int nx = qx[x[front]][y[front]];
        int ny = qy[x[front]][y[front]];
        if (xk == -1) xk = n - 1, --nx;
        if (xk == n) xk = 0, ++nx;
        if (yk == -1) yk = m - 1, --ny;
        if (yk == m) yk = 0, ++ny;
        if (G[xk][yk] == '#') continue;
        if (vis[xk][yk] && (qx[xk][yk] != nx || qy[xk][yk] != ny)) {
          printf("Yes\n");
          return 0;
        }
        if (!vis[xk][yk]) {
          rear++;
          x[rear] = xk;
          y[rear] = yk;
          vis[xk][yk] = true;
          qx[xk][yk] = nx;
          qy[xk][yk] = ny;
        }
      }
      front++;
    }
    printf("No\n");
  }
  return 0;
}
