#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
inline void checkmax(T& a, const T& b) {
  if (a < b) a = b;
}
const int maxn = 1500 + 5;
char m[maxn][maxn];
int fa[maxn * maxn + 5];
int dist[maxn * maxn + 5];
void print(int r, int c) {
  for (int i = 0; i <= r + 1; ++i) {
    for (int j = 0; j <= c + 1; ++j) {
      cout << m[i][j];
    }
    cout << endl;
  }
}
void init(int n) {
  for (int i = 0; i <= n; i++) fa[i] = i;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void unionset(int x, int y) {
  x = find(x);
  y = find(y);
  fa[x] = y;
}
vector<int> g1[maxn * maxn + 5], g2[maxn * maxn + 5];
int fabak[maxn * maxn + 5];
void backup(int fa[], int n) {
  for (int i = 0; i <= n; i++) {
    fabak[i] = fa[i];
    g1[i].clear();
    g2[i].clear();
    dist[i] = -1;
  }
}
void recover(int fa[], int n) {
  for (int i = 0; i <= n; i++) fa[i] = fabak[i];
}
void addedge(int a, int b) {
  a = find(a);
  b = find(b);
  g1[a].push_back(b);
  g2[b].push_back(a);
}
bool dfs(int u) {
  for (int i = 0; i < g1[u].size(); i++) {
    int v = g1[u][i];
    if (dist[v] == -1) {
      dist[v] = dist[u] + 1;
      if (dfs(v)) return 1;
    } else {
      if (dist[v] != dist[u] + 1) return 1;
    }
  }
  for (int i = 0; i < g2[u].size(); i++) {
    int v = g2[u][i];
    if (dist[v] == -1) {
      dist[v] = dist[u] - 1;
      if (dfs(v)) return 1;
    } else {
      if (dist[v] != dist[u] - 1) return 1;
    }
  }
  return 0;
}
int main() {
  int r, c;
  while (cin >> r >> c) {
    gets(m[0]);
    for (int i = 1; i <= r; i++) {
      gets(m[i] + 1);
      m[i][0] = m[i][c + 1] = '@';
    }
    for (int j = 0; j <= c + 1; j++) m[0][j] = m[r + 1][j] = '@';
    int si, sj;
    for (int i = 1; i <= r; i++) {
      for (int j = 1; j <= c; j++) {
        if (m[i][j] == 'S') {
          si = i;
          sj = j;
          m[i][j] = '.';
        }
      }
    }
    int s = ((si) * (c + 3) + (sj));
    int n = ((r) * (c + 3) + (c));
    init(n);
    for (int i = 1; i <= r; i++) {
      for (int j = 1; j <= c; j++) {
        if (m[i][j] == '.' && m[i][j + 1] == '.') {
          unionset(((i) * (c + 3) + (j)), ((i) * (c + 3) + (j + 1)));
        }
        if (m[i][j] == '.' && m[i + 1][j] == '.') {
          unionset(((i) * (c + 3) + (j)), ((i + 1) * (c + 3) + (j)));
        }
      }
    }
    int ok = 0;
    do {
      backup(fa, n);
      for (int j = 1; j <= c; j++) {
        if (m[1][j] == '.' && m[r][j] == '.') {
          unionset(((1) * (c + 3) + (j)), ((r) * (c + 3) + (j)));
        }
      }
      for (int i = 1; i <= r; i++) {
        if (m[i][1] == '.' && m[i][c] == '.') {
          addedge(((i) * (c + 3) + (1)), ((i) * (c + 3) + (c)));
        }
      }
      int ind = find(s);
      dist[ind] = maxn * maxn + 5;
      if (dfs(ind)) {
        ok = 1;
      }
      recover(fa, n);
    } while (0);
    do {
      backup(fa, n);
      for (int i = 1; i <= r; i++) {
        if (m[i][1] == '.' && m[i][c] == '.') {
          unionset(((i) * (c + 3) + (1)), ((i) * (c + 3) + (c)));
        }
      }
      for (int j = 1; j <= c; j++) {
        if (m[1][j] == '.' && m[r][j] == '.') {
          addedge(((1) * (c + 3) + (j)), ((r) * (c + 3) + (j)));
        }
      }
      int ind = find(s);
      dist[ind] = maxn * maxn + 5;
      if (dfs(ind)) {
        ok = 1;
      }
      recover(fa, n);
    } while (0);
    puts(ok ? "Yes" : "No");
  }
}
