#include <bits/stdc++.h>
using namespace std;
int n, m, sr, sc;
char Map[1501][1501];
int chk[1501][1501];
pair<int, int> visit[1501][1501];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
int flag;
void dfs(int r, int c, int vr, int vc) {
  if (chk[r][c]) {
    if (visit[r][c] == make_pair(vr, vc)) return;
    printf("Yes\n");
    exit(0);
  }
  chk[r][c] = 1;
  visit[r][c] = make_pair(vr, vc);
  for (int i = 0; i < 4; i++) {
    int tr = r + dr[i];
    int tc = c + dc[i];
    int tvr = vr;
    int tvc = vc;
    if (tr == -1) {
      tr = n - 1;
      tvr--;
    }
    if (tc == -1) {
      tc = m - 1;
      tvc--;
    }
    if (tr == n) {
      tr = 0;
      tvr++;
    }
    if (tc == m) {
      tc = 0;
      tvc++;
    }
    if (Map[tr][tc] != '#') dfs(tr, tc, tvr, tvc);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &Map[i][j]);
      if (Map[i][j] == 'S') {
        sr = i;
        sc = j;
      }
    }
  }
  dfs(sr, sc, 0, 0);
  printf("No\n");
  return 0;
}
