#include <bits/stdc++.h>
using namespace std;
const int maxn = 750000;
map<int, bool> was[1500000];
bool used[1500][1500];
int sx, sy, n, m, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
char a[1500][1500];
void dfs(int x, int y) {
  if (a[(x % n + n) % n][(y % m + m) % m] == '#') return;
  if (used[(x % n + n) % n][(y % m + m) % m]) {
    cout << "Yes";
    exit(0);
  }
  was[x + maxn][y] = true;
  used[(x % n + n) % n][(y % m + m) % m] = true;
  for (int i = 0; i < 4; ++i)
    if (was[x + dx[i] + maxn][y + dy[i]] == 0) dfs(x + dx[i], y + dy[i]);
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  dfs(sx, sy);
  cout << "No";
  return 0;
}
