#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
long long mod = 1e9 + 7;
double eps = 0.00000001;
double PI = acos(-1);
int g[1505][1505], ff = 0, vis[1550][1550], n, m;
char str[1550];
pair<int, int> s, vv[1550][1550];
int dx[10] = {0, 1, 0, -1};
int dy[10] = {1, 0, -1, 0};
struct node {
  int x, y;
};
int bfs(pair<int, int> ss) {
  queue<node> q;
  node st;
  st.x = ss.first, st.y = ss.second;
  vv[ss.first][ss.second] = pair<int, int>(ss.first, ss.second);
  memset(vis, 0, sizeof(vis));
  q.push(st);
  memset(vis, 0, sizeof(vis));
  while (!q.empty()) {
    node tmp = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int xx = tmp.x + dx[i], yy = tmp.y + dy[i], cx = xx, cy = yy;
      if (xx > n || xx < 1) cx = (xx % n + n) % n;
      if (yy > m || yy < 1) cy = (yy % m + m) % m;
      if (!cx) cx = n;
      if (!cy) cy = m;
      if (!g[cx][cy]) continue;
      node data;
      data.x = xx, data.y = yy;
      if (!vis[cx][cy]) {
        q.push(data);
        vv[cx][cy] = pair<int, int>(xx, yy);
        vis[cx][cy] = 1;
      } else if (pair<int, int>(xx, yy) != vv[cx][cy])
        return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str + 1);
    for (int j = 1; str[j]; j++) {
      if (str[j] == '#')
        g[i][j] = 0;
      else
        g[i][j] = 1;
      if (str[j] == 'S') s.first = i, s.second = j;
    }
  }
  if (bfs(s))
    puts("Yes");
  else
    puts("No");
}
