#include <bits/stdc++.h>
using namespace std;
using namespace std;
char s[1501][1501];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool vis[1501][1501] = {0};
int lstx[1501][1501], lsty[1501][1501];
int n, m;
bool dfs(int x, int y) {
  int nx = (x % n + n) % n, ny = (y % m + m) % m;
  if (s[nx][ny] == '#') return 0;
  if (vis[nx][ny]) return (x != lstx[nx][ny] || y != lsty[nx][ny]);
  lstx[nx][ny] = x;
  lsty[nx][ny] = y;
  vis[nx][ny] = 1;
  for (int i = 0; i < 4; ++i)
    if (dfs(x + dx[i], y + dy[i])) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", &s[i]);
  int sx, sy;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] == 'S') sx = i, sy = j;
  if (dfs(sx, sy))
    puts("YES");
  else
    puts("NO");
}
