#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, sx, sy;
char maze[MAXN][MAXN];
bool visited[MAXN][MAXN];
int last[2][MAXN][MAXN];
bool check(int i, int j) {
  int ii = (i % n + n) % n;
  int jj = (j % m + m) % m;
  visited[ii][jj] = true;
  last[0][ii][jj] = i;
  last[1][ii][jj] = j;
  for (int k = 0, ni, nj, nii, njj; k < 4; ++k) {
    ni = i + dx[k];
    nj = j + dy[k];
    nii = (ni % n + n) % n;
    njj = (nj % m + m) % m;
    if (maze[nii][njj] == '#') continue;
    if (!visited[nii][njj] && check(ni, nj))
      return true;
    else if (last[0][nii][njj] != ni || last[1][nii][njj] != nj)
      return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf(" %c", &maze[i][j]);
      if (maze[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  }
  if (check(sx, sy))
    puts("Yes");
  else
    puts("No");
  return 0;
}
