#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> g;
vector<vector<pair<int, int> > > was;
pair<int, int> undef((1UL << 31) - 1, 0);
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};
inline int rem(int x, int y) {
  x %= y;
  return (x < 0) ? x + y : x;
}
bool dfs(int x, int y) {
  int tx = rem(x, w);
  int ty = rem(y, h);
  if (was[ty][tx] != undef) {
    return was[ty][tx] != pair<int, int>(x, y);
  }
  was[ty][tx] = pair<int, int>(x, y);
  for (int d = 0; d < 4; ++d) {
    int nx = rem(x + dx[d], w);
    int ny = rem(y + dy[d], h);
    if (g[ny][nx] != '#' && dfs(x + dx[d], y + dy[d])) return true;
  }
  return false;
}
int main() {
  while (cin >> h >> w) {
    g.resize(h);
    was.resize(h);
    for (int y = 0; y < h; ++y) {
      cin >> g[y];
      was[y] = vector<pair<int, int> >(w, undef);
    }
    int y = -1, x = -1;
    for (y = 0; y < h; ++y) {
      for (x = 0; x < w; ++x) {
        if (g[y][x] == 'S') {
          break;
        }
      }
      if (x < w) {
        break;
      }
    }
    cout << (dfs(x, y) ? "Yes\n" : "No\n");
  }
  return 0;
}
