#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
char G[1510][1510];
pair<int, int> q[1510][1510];
bool vis[1510][1510];
struct node {
  int x;
  int y;
};
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool dfs(int xx, int yy) {
  int qx, qy;
  for (int k = 0; k < 4; ++k) {
    int nx = xx + dx[k];
    int ny = yy + dy[k];
    qx = q[xx][yy].first;
    qy = q[xx][yy].second;
    if (nx == -1) nx = n - 1, ++qx;
    if (nx == n) nx = 0, --qx;
    if (ny == -1) ny = m - 1, ++qy;
    if (ny == m) ny = 0, --qy;
    if (G[nx][ny] == '#') continue;
    if (vis[nx][ny] && (q[nx][ny].first != qx || q[nx][ny].second != qy))
      return true;
    if (!vis[nx][ny]) {
      vis[nx][ny] = true;
      q[nx][ny].first = qx;
      q[nx][ny].second = qy;
      if (dfs(nx, ny)) return true;
    }
  }
  return 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 = i, y = j;
      }
    }
    memset(vis, false, sizeof(vis));
    memset(q, 0, sizeof(q));
    vis[x][y] = true;
    if (dfs(x, y))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
