#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
char mp[maxn][maxn];
int n, m;
const int dir_x[4] = {1, -1, 0, 0};
const int dir_y[4] = {0, 0, 1, -1};
pair<int, int> last[maxn][maxn];
bool ret = false;
void dfs(int x, int y) {
  int mx = x % n, my = y % m;
  if (mp[mx][my] == '#' || ret || last[mx][my] == pair<int, int>(x, y)) return;
  if (last[mx][my] != pair<int, int>(0, 0)) {
    ret = true;
    return;
  }
  last[mx][my] = pair<int, int>(x, y);
  for (int i = 0; i < 4; i++) {
    dfs(x + dir_x[i], y + dir_y[i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  int sx, sy;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j] == 'S') sx = i, sy = j;
    }
  }
  dfs(sx + n * m, sy + n * m);
  if (ret)
    puts("Yes");
  else
    puts("No");
  return 0;
}
