#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const double EPS = 1e-5;
int n, m;
vector<string> g;
vector<vector<bool> > vis;
pair<int, int> pos;
inline bool out(int i, int j) { return i < 0 || j < 0 || i >= n || j >= m; }
bool ff(int x, int y) {
  if (g[x][y] == 'S') return true;
  vis[x][y] = true;
  bool ret = false;
  for (int i = 0; i < 4; i++) {
    int xi = x + di[i], yi = y + dj[i];
    if (out(xi, yi)) {
      xi = (xi + n) % n;
      yi = (yi + m) % m;
    }
    if (g[xi][yi] != '#' && !vis[xi][yi]) ret = (ret || ff(xi, yi));
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
    for (int j = 0; j < m; j++)
      if (g[i][j] == 'S') {
        pos.first = i;
        pos.second = j;
        break;
      }
  }
  for (int i = 0; i < n; i++) g[i] += g[i];
  vector<string> og = g;
  g.insert(g.end(), og.begin(), og.end());
  n *= 2, m *= 2;
  g[pos.first][pos.second] = '.';
  vis.assign(n, vector<bool>(m, false));
  cout << (ff(pos.first, pos.second) ? "Yes" : "No") << endl;
  cin.ignore(), cin.get();
}
