#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int N = int(3e5 + 7);
int n, m, cur, ox, oy;
int dx[] = {0, -1, 1, 0};
int dy[] = {1, 0, 0, -1};
char c[1555][1555];
pair<int, int> u[1555][1555];
void dfs(int x, int y) {
  int nx = x % n, ny = y % m;
  while (nx < 0) nx += n;
  while (ny < 0) ny += m;
  if (c[nx][ny] == '#') return;
  if (u[nx][ny] == make_pair(-1, -1))
    u[nx][ny] = make_pair(x, y);
  else if (u[nx][ny] != make_pair(x, y)) {
    puts("Yes");
    exit(0);
  } else
    return;
  u[nx][ny] = make_pair(x, y);
  for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", c[i]);
  memset(u, -1, sizeof u);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (c[i][j] == 'S') ox = i, oy = j;
  dfs(ox, oy);
  puts("No");
  return 0;
}
