#include <bits/stdc++.h>
using namespace std;
const int maxn = 1500 + 5;
const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, 1, -1, 0};
int n, m, st_x, st_y;
bool found;
pair<int, int> mark[maxn][maxn];
char S[maxn][maxn];
void dfs(int x, int y, int real_x, int real_y) {
  if (mark[x][y] != make_pair(-1, -1)) {
    if (mark[x][y] != make_pair(real_x, real_y)) found = true;
    return;
  }
  mark[x][y] = make_pair(real_x, real_y);
  for (int i = 0; i < 4; i++)
    if ((S[(x + dx[i] + n) % n][(y + dy[i] + m) % m] != '#') && !found)
      dfs((x + dx[i] + n) % n, (y + dy[i] + m) % m, real_x + dx[i],
          real_y + dy[i]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", S[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (S[i][j] == 'S') {
        st_x = i;
        st_y = j;
        break;
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) mark[i][j] = make_pair(-1, -1);
  dfs(st_x, st_y, st_x, st_y);
  if (found)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
