#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0};
int flag, n, m;
char s[2000][2000];
pair<int, int> p[2000][2000], temp;
void dfs(int r, int c) {
  int i, j, t1, t2, t3, t4, r1, c1, r2, c2;
  for (i = 0; i < 4; i++) {
    r1 = r + dr[i];
    c1 = c + dc[i];
    r2 = r1;
    c2 = c1;
    r1 = (r1 % n + n) % n;
    c1 = (c1 % m + m) % m;
    if (s[r1][c1] == '#') continue;
    if (p[r1][c1] == temp) {
      p[r1][c1] = make_pair(r2, c2);
      dfs(r2, c2);
    } else {
      if (p[r1][c1] != make_pair(r2, c2)) {
        flag = 1;
      }
    }
  }
  return;
}
int main() {
  int i, j, t1, t2, t3, t4, rs, cs;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  temp = make_pair(1e9, 1e9);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        rs = i;
        cs = j;
      }
      p[i][j] = temp;
    }
  }
  flag = 0;
  p[rs][cs] = make_pair(rs, cs);
  dfs(rs, cs);
  if (flag == 1)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
