#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 11) + 1;
char maze[MAXN][MAXN];
int vis[MAXN * MAXN];
pair<int, int> sum[MAXN * MAXN];
int p[MAXN * MAXN];
int r[MAXN * MAXN];
int n, m;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int repr(int v) {
  if (p[v] != v) p[v] = repr(p[v]);
  return p[v];
}
void join(int a, int b) {
  a = repr(a);
  b = repr(b);
  if (a != b) {
    if (r[a] <= r[b]) {
      p[a] = b;
      if (r[a] == r[b]) r[b]++;
    } else
      p[b] = a;
  }
}
map<int, set<pair<int, pair<int, int> > > > E;
void addEdge(int x1, int y1, int x2, int y2, int a, int b) {
  int v = repr(x1 * m + y1);
  int u = repr(x2 * m + y2);
  if (0) printf("addEdge(%d, %d)\n", v, u);
  E[v].insert(pair<int, pair<int, int> >(u, pair<int, int>(1 * a, 1 * b)));
  E[u].insert(pair<int, pair<int, int> >(v, pair<int, int>(-1 * a, -1 * b)));
}
bool dfs(int v, int parent, pair<int, int> s) {
  if (vis[v]) return s != sum[v];
  sum[v] = s;
  vis[v] = true;
  set<pair<int, pair<int, int> > > &e = E[v];
  for (__typeof((e).end()) u = (e).begin(); u != (e).end(); ++u) {
    if (u->first == parent) continue;
    pair<int, int> ss = u->second;
    if (dfs(u->first, v,
            pair<int, int>(s.first + ss.first, s.second + ss.second)))
      return true;
  }
  return false;
}
bool check() {
  int sidx;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      p[i * m + j] = i * m + j;
      r[i * m + j] = 0;
      vis[i * m + j] = false;
    }
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      if (maze[i][j] == 'S') sidx = i * m + j;
      if (maze[i][j] != '#')
        for (int k = 0; k < (4); ++k) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (nx < 0 or nx >= n or ny < 0 or ny >= m or maze[nx][ny] == '#')
            continue;
          join(i * m + j, nx * m + ny);
        }
    }
  if (0) {
    for (int i = 0; i < (n); ++i) {
      for (int j = 0; j < (m); ++j) printf("%2d ", repr(i * m + j));
      printf("\n");
    }
  }
  for (int i = 0; i < (n); ++i)
    if (maze[i][0] != '#' and maze[i][m - 1] != '#')
      addEdge(i, 0, i, m - 1, 1, 0);
  for (int i = 0; i < (m); ++i)
    if (maze[0][i] != '#' and maze[n - 1][i] != '#')
      addEdge(0, i, n - 1, i, 0, 1);
  return dfs(repr(sidx), -1, pair<int, int>(0, 0));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%s", maze[i]);
  printf("%s\n", check() ? "Yes" : "No");
  return 0;
}
