#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int inf = 0x7FFFFFFF;
template <class T>
inline bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
int vis[1505][1505];
pair<int, int> msk[1505][1505];
char ch[1505][1505];
int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < int(n); i++) scanf("%s", ch[i]);
    memset(vis, -1, sizeof(vis));
    queue<int> q;
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(m); j++)
        if (ch[i][j] == 'S') {
          q.push((i << 15) + j);
          vis[i][j] = 0;
          msk[i][j] = make_pair(0, 0);
        }
    bool yes = false;
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      int x = f >> 15, y = f ^ (x << 15);
      int dx = msk[x][y].first, dy = msk[x][y].second;
      for (int i = 0; i < int(4); i++) {
        int u = x + dir[i][0], v = y + dir[i][1];
        int tx = dx, ty = dy;
        if (u < 0) u += n, tx--;
        if (u >= n) u -= n, tx++;
        if (v < 0) v += m, ty--;
        if (v >= m) v -= m, ty++;
        pair<int, int> mask = make_pair(tx, ty);
        if (ch[u][v] == '#') continue;
        if (vis[u][v] == -1) {
          vis[u][v] = 0;
          msk[u][v] = mask;
          q.push((u << 15) + v);
        }
        if (msk[u][v] != mask) yes = true;
      }
    }
    puts(yes ? "Yes" : "No");
  }
  return 0;
}
