#include <bits/stdc++.h>
using namespace std;
const int N = 1510;
int n, m, st, en;
bool vld = false;
pair<int, int> vis[1510][1510];
char a[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void dfs(int x, int y) {
  int nxx = (x + n * n) % n;
  int nyy = (y + m * m) % m;
  vis[nxx][nyy] = {x, y};
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    int nxxx = (nx + n * n) % n, nyyy = (ny + m * m) % m;
    if (pair<int, int>{nx, ny} != vis[nxxx][nyyy] &&
        vis[nxxx][nyyy] != pair<int, int>{1e9, 1e9}) {
      vld = true;
      return;
    } else if (vis[nxxx][nyyy] == pair<int, int>{1e9, 1e9} &&
               a[nxxx][nyyy] == '.')
      dfs(nx, ny);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') st = i, en = j;
    }
  }
  for (int i = 0; i < 1510; i++) {
    for (int j = 0; j < m; j++) {
      vis[i][j] = {1e9, 1e9};
    }
  }
  dfs(st, en);
  if (vld)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
