#include <bits/stdc++.h>
using namespace std;
struct node{
int x, y;
};
int n, m, sx, sy;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int b[1502][1502];
int b2[4502][4502];
char a[1502][1502];
queue<node> q;
bool check(int x, int y) {
if (a[x % n][y % m] != '#' && !b2[x][y] && x >= 0 && x < n * 3 && y >= 0 && y < m * 3)
return true;
else
return false;
}
int main() {
while ((scanf("%d%d", &n, &m)) != EOF) {
for (int i = 0; i < n; i++)
scanf("%s", a[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == 'S')
sx = i, sy = j;
sx += n, sy += m;
memset(b2, 0, sizeof(b2));
memset(b, 0, sizeof(b));
b2[sx][sy] = 1;
b[sx % n][sy % m] = 1;
q = queue<node> {};
q.push({sx, sy});
int ok = 0;
while(q.size() && !ok) {
int nx = q.front().x;
int ny = q.front().y;
q.pop();
for (int k = 0; k < 4; k++) {
int tx = nx + dx[k];
int ty = ny + dy[k];
if (check(tx, ty)) {
b2[tx][ty] = 1;
if (b[tx % n][ty % m]) {
ok = 1;
}
else
b[tx % n][ty % m] = 1, q.push({tx, ty});
}
}
}
if (ok)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}