#include <bits/stdc++.h>
using namespace std;
const int N = 1600, INF = 0x3f3f3f3f;
int n, m, sx, sy;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
pair<int, int> pmap[N][N];
char Map[N][N];
bool dfs(int x, int y, int xx, int yy) {
  if (xx == pmap[x][y].first && yy == pmap[x][y].second) return 1;
  if (pmap[x][y].first == INF || pmap[x][y].second == INF)
    pmap[x][y].first = xx, pmap[x][y].second = yy;
  else
    return 0;
  for (int i = 0, nx, ny; i < 4; i++) {
    nx = x + dx[i], ny = y + dy[i];
    nx = (nx + n - 1) % n + 1, ny = (ny + m - 1) % m + 1;
    if (Map[nx][ny] == '#') continue;
    if (!dfs(nx, ny, xx + dx[i], yy + dy[i])) return 0;
  }
  return 1;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(pmap, 0x3f, sizeof(pmap));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cin >> Map[i][j];
        if (Map[i][j] == 'S') sx = i, sy = j;
      }
    puts(!dfs(sx, sy, sx, sy) ? "Yes" : "No");
  }
  return 0;
}
