#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
long long n, m, dx[5] = {1, 0, -1, 0}, dy[5] = {0, 1, 0, -1},
                vis[3][1500][1500], st_x, st_y;
const int maxn = 1500 + 5;
char ch[maxn][maxn];
bool mp[maxn][maxn], flag;
inline void dfs(int x, int y, int xx, int yy) {
  if (flag) return;
  if (vis[0][xx][yy] && (vis[1][xx][yy] != x || vis[2][xx][yy] != y)) {
    flag = true;
    return;
  }
  if (vis[0][xx][yy] && vis[1][xx][yy] == x && vis[2][xx][yy] == y) return;
  vis[0][xx][yy] = 1;
  vis[1][xx][yy] = x;
  vis[2][xx][yy] = y;
  for (int i = 0; i <= 3; i++) {
    int xxx = (xx + dx[i] + n) % n, yyy = (yy + dy[i] + m) % m;
    if (mp[xxx][yyy]) dfs(x + dx[i], y + dy[i], xxx, yyy);
  }
}
int main() {
  n = read();
  m = read();
  flag = false;
  memset(mp, false, sizeof(mp));
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ch[i][j] = getchar();
      if (ch[i][j] == '.') mp[i][j] = true;
      if (ch[i][j] == '#') mp[i][j] = false;
      if (ch[i][j] == 'S') {
        st_x = i, st_y = j;
        mp[i][j] = true;
      }
    }
    getchar();
  }
  dfs(st_x, st_y, st_x, st_y);
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
