#include <bits/stdc++.h>
using namespace std;
char a[1510][1510];
int dx[6], dy[6], vis[1510][1510][2];
int n, m, sx, sy;
bool dfs(int x, int y) {
  int fx = (x % n + n) % n, fy = (y % m + m) % m;
  if (a[fx][fy] == '#') return false;
  if (vis[fx][fy][0] != 0x3f3f3f)
    return vis[fx][fy][0] != x || vis[fx][fy][1] != y;
  vis[fx][fy][0] = x, vis[fx][fy][1] = y;
  for (int i = 1; i <= 4; ++i)
    if (dfs(x + dx[i], y + dy[i])) return true;
  return false;
}
int main() {
  dx[1] = 0, dx[2] = 0, dx[3] = -1, dx[4] = 1;
  dy[1] = -1, dy[2] = 1, dy[3] = 0, dy[4] = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == 'S') sx = i, sy = j;
      vis[i][j][0] = 0x3f3f3f;
    }
  }
  if (dfs(sx, sy))
    printf("Yes");
  else
    printf("No");
  return 0;
}
