#include <bits/stdc++.h>
using namespace std;
const int maxn = 1505;
int n, m;
char mp[maxn][maxn];
bool mark[maxn][maxn];
pair<int, int> adj[maxn][maxn];
int xo[] = {1, 0, -1, 0};
int yo[] = {0, 1, 0, -1};
pair<int, int> alaf[maxn][maxn];
bool jvb = false;
void dfs(int x, int y, int jx, int jy) {
  mark[x][y] = true;
  adj[x][y].first = jx;
  adj[x][y].second = jy;
  for (int i = 0; i < 4; i++) {
    int l, r, cx, cy;
    l = x + xo[i];
    r = y + yo[i];
    cx = jx;
    cy = jy;
    if (l == n) {
      l = 0;
      cx++;
    }
    if (l < 0) {
      l = n - 1;
      cx--;
    }
    if (r == m) {
      r = 0;
      cy++;
    }
    if (r < 0) {
      r = m - 1;
      cy--;
    }
    if (mp[l][r] == '#') {
      continue;
    }
    if ((cx != adj[l][r].first || cy != adj[l][r].second) && mark[l][r])
      jvb = true;
    if (mark[l][r]) continue;
    dfs(l, r, cx, cy);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  pair<int, int> alaki;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> mp[i][j];
      if (mp[i][j] == 'S') {
        alaki.first = i;
        alaki.second = j;
      }
    }
  dfs(alaki.first, alaki.second, 0, 0);
  cout << (jvb ? "YES" : "NO") << endl;
}
