#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> g(n);
  int sx, sy;
  for (int i = (int)0; i < (int)n; ++i) {
    cin >> g[i];
    for (int j = (int)0; j < (int)m; ++j)
      if (g[i][j] == 'S') sx = i, sy = j;
  }
  vector<int> vis(n * m, KINF);
  vis[sx * m + sy] = sx * m + sy;
  queue<pair<int, int> > q;
  q.push({sx, sy});
  int d[5] = {0, 1, 0, -1, 0};
  while (!q.empty()) {
    auto [x, y] = q.front();
    q.pop();
    for (int k = (int)0; k < (int)4; ++k) {
      int nx = x + d[k], ny = y + d[k + 1];
      int ox = (nx % n + n) % n, oy = (ny % m + m) % m;
      if (g[ox][oy] == '#') continue;
      if (vis[ox * m + oy] == KINF) {
        q.push({nx, ny});
        vis[ox * m + oy] = nx * m + ny;
      } else if (vis[ox * m + oy] != nx * m + ny) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}
