#include <bits/stdc++.h>
using namespace std;
pair<int, int> vis[1505][1505];
char s[1505][1505];
int v[1505][1505];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n, m, sx, sy;
int flag;
void dfs(int x, int y) {
  int nx = (x % n + n) % n, ny = (y % m + m) % m;
  if (s[nx][ny] == '#') return;
  if (v[nx][ny]) {
    if (vis[nx][ny].first != x || vis[nx][ny].second != y) flag = 1;
    return;
  } else {
    v[nx][ny] = 1;
    vis[nx][ny] = make_pair(x, y);
  }
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    dfs(nx, ny);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    memset(v, 0, sizeof(v));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (s[i][j] == 'S') {
          sx = i, sy = j;
        }
      }
    flag = 0;
    dfs(sx, sy);
    if (flag)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
