#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1505;
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
int n, m;
int a[MaxN][MaxN];
bool mark[MaxN][MaxN];
int x[MaxN * MaxN], y[MaxN * MaxN];
int fx[MaxN][MaxN], fy[MaxN][MaxN];
bool good(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
int main() {
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  char s[MaxN];
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] == 'S') {
        x[1] = i;
        y[1] = j;
      }
      if (s[j] == '#') a[i][j] = 1;
    }
  }
  memset(mark, 0, sizeof(mark));
  memset(fx, 0, sizeof(fx));
  memset(fy, 0, sizeof(fy));
  int i = 1, j = 1;
  mark[x[1]][y[1]] = true;
  while (i <= j) {
    int z = j;
    for (int q = i; q <= j; q++)
      for (int k = 0; k < 4; k++) {
        int nx = x[q] + di[k];
        int ny = y[q] + dj[k];
        int xx = fx[x[q]][y[q]];
        int yy = fy[x[q]][y[q]];
        if (nx == 0) nx = n, xx--;
        if (nx == n + 1) nx = 1, xx++;
        if (ny == 0) ny = m, yy--;
        if (ny == m + 1) ny = 1, yy++;
        if (mark[nx][ny] && !(fx[nx][ny] == xx && fy[nx][ny] == yy)) {
          printf("Yes\n");
          return 0;
        }
        if (!mark[nx][ny] && !a[nx][ny]) {
          mark[nx][ny] = true;
          fx[nx][ny] = xx;
          fy[nx][ny] = yy;
          z++;
          x[z] = nx;
          y[z] = ny;
        }
      }
    i = j + 1;
    j = z;
  }
  printf("No\n");
  return 0;
}
