#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510, dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int ha[maxn][maxn][2], v[maxn][maxn], i, j, k, t, m, n, p, x, y, bex, bey;
char c;
int dfs(int nowx, int nowy) {
  int i, tox, toy, x = (nowx % n + n) % n, y = (nowy % m + m) % m;
  if (ha[x][y][0] >= (INT_MAX >> 1)) {
    ha[x][y][0] = nowx;
    ha[x][y][1] = nowy;
  } else if ((ha[x][y][0] != nowx) || (ha[x][y][1] != nowy))
    return 1;
  else
    return 0;
  for (i = 0; i <= 3; i++) {
    tox = nowx + dx[i];
    toy = nowy + dy[i];
    if (v[(tox % n + n) % n][(toy % m + m) % m])
      if (dfs(tox, toy)) return 1;
  }
  return 0;
}
int main() {
  while (scanf("%d%d\n", &n, &m) > 0) {
    for (i = 0; i <= n - 1; i++) {
      for (j = 0; j <= m - 1; j++) {
        ha[i][j][0] = ha[i][j][1] = INT_MAX >> 1;
        scanf("%c", &c);
        if (c == '#') {
          v[i][j] = 0;
          continue;
        }
        if (c == '.') {
          v[i][j] = 1;
          continue;
        }
        if (c == 'S') {
          v[i][j] = 1;
          bex = i;
          bey = j;
        }
      }
      getchar();
    }
    if (dfs(bex, bey))
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
