#include <bits/stdc++.h>
using namespace std;
const int maxn = 1500 + 10;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
bool mark[maxn][maxn];
int n, m, bomb;
char mat[maxn][maxn];
pair<int, int> jad[maxn][maxn];
void dfs(int v, int u) {
  if (bomb == 1) return;
  int v1 = v % n;
  if (v1 < 0) v1 += n;
  int u1 = u % m;
  if (u1 < 0) u1 += m;
  mark[v1][u1] = true;
  jad[v1][u1].first = v;
  jad[v1][u1].second = u;
  for (int i = 0; i < 4; i++) {
    if (bomb == 1) break;
    int x1 = v + dx[i];
    int y1 = u + dy[i];
    int x2 = x1 % n;
    if (x2 < 0) x2 += n;
    int y2 = y1 % m;
    if (y2 < 0) y2 += m;
    if (mark[x2][y2] && mat[x2][y2] != '#' &&
        (jad[x2][y2].first != x1 || jad[x2][y2].second != y1)) {
      cout << "Yes" << endl;
      bomb = 1;
    }
    if (!mark[x2][y2] && mat[x2][y2] != '#') dfs(x1, y1);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mat[i][j] == 'S') dfs(i, j);
  if (!bomb) cout << "No" << endl;
  return 0;
}
