#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M; cin >> N >> M;
vector<string> g(N);
long long sx = 0, sy = 0;
for (int i = 0; i < N; i++) {
cin >> g[i];
for (int j = 0; j < M; j++) if (g[i][j] == 'S') { sx = i; sy = j; }
}
vector<vector<long long>> ox(N, vector<long long>(M, LLONG_MAX));
vector<vector<long long>> oy(N, vector<long long>(M, LLONG_MAX));
queue<pair<long long,long long>> q;
q.push({sx, sy});
ox[sx][sy] = sx; oy[sx][sy] = sy;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
bool yes = false;
while (!q.empty()) {
auto [x, y] = q.front(); q.pop();
int mx = (int)((x % N + N) % N), my = (int)((y % M + M) % M);
for (int d = 0; d < 4; d++) {
long long nx = x + dx[d], ny = y + dy[d];
int nmx = (int)((nx % N + N) % N), nmy = (int)((ny % M + M) % M);
if (g[nmx][nmy] == '#') continue;
if (ox[nmx][nmy] != LLONG_MAX) {
// 已访问过该模位置
if (abs(nx - ox[nmx][nmy]) >= N || abs(ny - oy[nmx][nmy]) >= M) {
yes = true; break;
}
} else {
ox[nmx][nmy] = nx; oy[nmx][nmy] = ny;
q.push({nx, ny});
}
}
if (yes) break;
}
cout << (yes ? "Yes" : "No") << endl;
return 0;
}