#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
char mp[maxn][maxn];
bool vis[maxn][maxn];
pair<int, int> mark[maxn][maxn];
int n, m;
int sx, sy;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void dfs(int x, int y) {
  int tx = (x % n + n) % n, ty = (y % m + m) % m;
  if (mp[tx][ty] == '#') return;
  if (vis[tx][ty]) {
    if (mark[tx][ty].first != x || mark[tx][ty].second != y) {
      cout << "Yes" << endl;
      exit(0);
    }
    return;
  } else {
    vis[tx][ty] = true;
    mark[tx][ty] = make_pair(x, y);
  }
  for (int i = 0; i <= 3; i++) {
    dfs(x + dir[i][0], y + dir[i][1]);
  }
}
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    getchar();
    for (int j = 0; j < m; j++) {
      scanf("%c", &mp[i][j]);
      if (mp[i][j] == 'S') sx = i, sy = j;
    }
  }
  dfs(sx, sy);
  cout << "No" << endl;
  return 0;
}
