#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
void File() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
char maze[1502][1502];
char ss[5005][5005];
struct node {
  int x, y;
  node() {}
  node(int x, int y) : x(x), y(y) {}
} s;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool vis[5005][5005];
int K;
bool bfs(node s, int n, int m) {
  queue<node> q;
  vis[s.x][s.y] = true;
  node u, v;
  q.push(s);
  ss[s.x][s.y] = '.';
  while (!q.empty()) {
    u = q.front();
    q.pop();
    int x = u.x;
    int y = u.y;
    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!(nx >= 0 && nx < 3 * n && ny >= 0 && ny < 3 * m)) {
        nx = (nx + 3 * n) % (3 * n);
        ny = (ny + 3 * m) % (3 * m);
      }
      if (vis[nx][ny]) {
        continue;
      }
      if (ss[nx][ny] == '#') continue;
      vis[nx][ny] = true;
      if (!(nx >= n && nx < 2 * n && ny >= m && ny < 2 * m)) {
        if (vis[nx % n + n][ny % m + m]) K++;
        if (K >= 2) return true;
      }
      if (ss[nx][ny] == 'S') return true;
      q.push(node(nx, ny));
    }
  }
  return false;
}
int main() {
  int i, j;
  int n, m;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i) scanf("%s", maze[i]);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; j++) {
      if (maze[i][j] == 'S') {
        s = node(i + n, j + m);
        break;
      }
    }
  }
  for (i = 0; i < 3 * n; ++i) {
    for (j = 0; j < 3 * m; ++j) {
      ss[i][j] = maze[i % n][j % m];
    }
  }
  if (bfs(s, n, m))
    puts("Yes");
  else
    puts("No");
  return 0;
}
