#include <bits/stdc++.h>
using namespace std;
const int N = 1600;
const int INF = 0x3f3f3f3f;
char ch[N][N];
int n, m;
int d[9][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
struct node {
  int x, y;
  node() {}
  node(int x, int y) : x(x), y(y) {}
} vis[N][N], Start, Cur;
bool bfs() {
  queue<node> q;
  q.push(Start);
  vis[Start.x][Start.y].x = Start.x;
  vis[Start.x][Start.y].y = Start.y;
  while (!q.empty()) {
    Cur = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x1 = Cur.x + d[i][0];
      int y1 = Cur.y + d[i][1];
      int x2 = x1 % n;
      int y2 = y1 % m;
      if (x2 < 0) x2 += n;
      if (y2 < 0) y2 += m;
      if (vis[x2][y2].x == -INF && vis[x2][y2].y == -INF && ch[x2][y2] != '#') {
        vis[x2][y2].x = x1;
        vis[x2][y2].y = y1;
        q.push(node(x1, y1));
      } else if ((vis[x2][y2].x != x1 || vis[x2][y2].y != y1) &&
                 ch[x2][y2] != '#' && (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m))
        return true;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) vis[i][j].x = vis[i][j].y = -INF;
  for (int i = 0; i < n; i++) scanf("%s", ch[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (ch[i][j] == 'S') Start.x = i, Start.y = j;
  puts(bfs() ? "Yes" : "No");
}
