#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
char a[1505][1505];
int vis[1505][1505][2];
int F[1505][1505];
int dis[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct node {
  int x, y;
};
int n, m;
bool bfs(int si, int sj) {
  queue<node> q;
  node cur, next;
  cur.x = si;
  cur.y = sj;
  q.push(cur);
  memset(F, 0, sizeof(F));
  while (!q.empty()) {
    cur = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      next.x = cur.x + dis[i][0];
      next.y = cur.y + dis[i][1];
      int x = ((next.x % n) + n) % n;
      int y = ((next.y % m) + m) % m;
      if (a[x][y] == '#') continue;
      if (F[x][y]) {
        if (next.x != vis[x][y][0] || next.y != vis[x][y][1]) return true;
      } else {
        F[x][y] = 1;
        vis[x][y][0] = next.x;
        vis[x][y][1] = next.y;
        q.push(next);
      }
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  getchar();
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  int si, sj;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'S') {
        si = i;
        sj = j;
        break;
      }
    }
  bool ff = bfs(si, sj);
  if (ff)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
