#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500 + 50;
char a[MAXN][MAXN];
bool mark[MAXN][MAXN];
int prex[MAXN][MAXN], prey[MAXN][MAXN];
int b[] = {0, -1, 0, 1}, c[] = {1, 0, -1, 0};
int n, m;
bool DFS(int x, int y) {
  int tmp1 = (x % n + n) % n, tmp8 = (y % m + m) % m;
  if (a[tmp1][tmp8] == '#') return false;
  if (mark[tmp1][tmp8]) {
    if (prex[tmp1][tmp8] == x && prey[tmp1][tmp8] == y) return false;
    return true;
  }
  prex[tmp1][tmp8] = x, prey[tmp1][tmp8] = y;
  mark[tmp1][tmp8] = true;
  for (int i = 0; i < 4; i++)
    if (DFS(x + b[i], y + c[i])) return true;
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'S') cout << (DFS(i, j) ? "YES" : "NO") << endl;
  return 0;
}
