#include <bits/stdc++.h>
using namespace std;
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n, m, si, sj;
char a[2000][2000];
int vis[2000][2000];
map<pair<int, int>, int> mp;
bool b = 0;
void dfs(int i, int j) {
  if (b) return;
  int ii = i, jj = j;
  while (i < 0) i += n;
  while (j < 0) j += m;
  if (i >= n) i %= n;
  if (j >= m) j %= m;
  if ((vis[i][j] && mp[{ii, jj}]) || a[i][j] == '#') return;
  if (vis[i][j] && mp[{ii, jj}] == 0) {
    b = 1;
    return;
  }
  vis[i][j] = 1;
  mp[{ii, jj}] = 1;
  dfs(ii, jj + 1);
  dfs(ii, jj - 1);
  dfs(ii + 1, jj);
  dfs(ii - 1, jj);
}
int main() {
  fast();
  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') si = i, sj = j;
    }
  }
  mp[{si, sj}] = 1;
  dfs(si, sj);
  if (b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
