#include <bits/stdc++.h>
using namespace std;
const int N = 1500 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
char maze[N][N];
int dis[N][N];
pair<int, int> vis[N][N];
int n, m;
bool check(int x, int y) {
  if (maze[(x % n + n) % n][(y % m + m) % m] == '#')
    return false;
  else
    return true;
}
bool DFS(int x, int y) {
  int hx = (x % n + n) % n;
  int hy = (y % m + m) % m;
  if (vis[hx][hy] != pair<int, int>(-1, -1)) {
    if (vis[hx][hy] != pair<int, int>(x, y))
      return true;
    else
      return false;
  }
  vis[hx][hy] = pair<int, int>(x, y);
  for (int i = 0; i < 4; ++i) {
    int tx = x + dx[i];
    int ty = y + dy[i];
    if (!check(tx, ty)) continue;
    if (DFS(tx, ty)) return true;
  }
  return false;
}
bool solve(int sx, int sy) {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) vis[i][j] = pair<int, int>(-1, -1);
  if (DFS(sx, sy))
    return true;
  else
    return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  int sx = -1, sy = -1;
  for (int i = 0; i < n; ++i) {
    cin >> maze[i];
    if (sx != -1) continue;
    for (int j = 0; j < m; ++j) {
      if (maze[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  }
  cout << (solve(sx, sy) ? "Yes" : "No") << '\n';
  return 0;
}
