#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
char mmap[N][N];
bool vis[N][N];
pair<int, int> record[N][N];
int n, m;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
struct Node {
  int x, y;
  Node(int x, int y) : x(x), y(y) {}
};
bool bfs(int x, int y) {
  queue<Node> q;
  q.push(Node(x, y));
  while (!q.empty()) {
    Node cur = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int __x = cur.x + dx[i];
      int __y = cur.y + dy[i];
      int _x = (__x % n + n) % n;
      int _y = (__y % m + m) % m;
      if (mmap[_x][_y] == '#') continue;
      if (vis[_x][_y]) {
        if (record[_x][_y].first != __x || record[_x][_y].second != __y)
          return true;
      } else {
        vis[_x][_y] = true;
        record[_x][_y] = make_pair(__x, __y);
        q.push(Node(__x, __y));
      }
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mmap[i]);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mmap[i][j] == 'S') {
        x = i, y = j;
        goto end;
      }
end:
  puts(bfs(x, y) ? "Yes" : "No");
  return 0;
}
