#include <bits/stdc++.h>
using namespace std;
struct nd {
  int fx, fy, v;
};
struct node {
  nd f[2003][2003];
  void init() { memset(f, 0, sizeof(f)); }
} vis;
bool mp[2003][2003], fl;
int n, m, s, t;
const int dx[5] = {0, 1, -1, 0, 0};
const int dy[5] = {0, 0, 0, 1, -1};
char c;
void search(int x, int y, int kx, int ky) {
  if (vis.f[kx][ky].v && (vis.f[kx][ky].fx != x || vis.f[kx][ky].fy != y)) {
    fl = 1;
    return;
  }
  if (vis.f[kx][ky].v && vis.f[kx][ky].fx == x && vis.f[kx][ky].fy == y) return;
  vis.f[kx][ky].v = 1;
  vis.f[kx][ky].fx = x;
  vis.f[kx][ky].fy = y;
  for (int i = 1; i <= 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    int gx = xx, gy = yy;
    while (gx < 0) gx += n;
    while (gy < 0) gy += m;
    gx %= n;
    gy %= m;
    if (!mp[gx][gy]) continue;
    search(xx, yy, gx, gy);
    if (fl) return;
  }
  return;
}
int read() {
  char ch = getchar();
  int num = 0;
  for (; !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); ch = getchar()) num = (num << 1) + (num << 3) + ch - 48;
  return num;
}
int main() {
  n = read();
  m = read();
  fl = 0;
  memset(mp, 0, sizeof(mp));
  vis.init();
  register int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      c = getchar();
      while (c != 'S' && c != '#' && c != '.') c = getchar();
      if (c == 'S') {
        s = i;
        t = j;
      }
      mp[i][j] = !(c == '#');
    }
  search(s, t, s, t);
  if (fl)
    puts("Yes");
  else
    puts("No");
  return 0;
}
