#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3;
char mp[maxn][maxn];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
pair<int, int> vis[maxn][maxn];
int n, m, xb, yb, cntx = 0, cnty = 0;
bool flag = 0;
void dfs(int x, int y, int prex, int prey) {
  int xx = x % n, yy = y % m;
  if (xx < 0) xx += n;
  if (yy < 0) yy += m;
  if (mp[xx][yy] == '#') return;
  if (vis[xx][yy].first == -1 && vis[xx][yy].second - 1)
    vis[xx][yy] = make_pair(x, y);
  else if (vis[xx][yy] != make_pair(x, y)) {
    printf("Yes\n");
    exit(0);
  } else
    return;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx != prex || ny != prey) dfs(nx, ny, x, y);
  }
}
int main() {
  memset(vis, -1, sizeof(vis));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", mp[i]);
    for (int j = 0; j < m; j++)
      if (mp[i][j] == 'S') {
        xb = i;
        yb = j;
      }
  }
  dfs(xb, yb, -1, -1);
  printf("No\n");
}
