#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 (ii < 0) ii += n;
  while (jj < 0) jj += m;
  if (ii >= n) ii %= n;
  if (jj >= m) jj %= m;
  if (a[ii][jj] == '#' || (vis[ii][jj] && mp[{i, j}])) return;
  if ((vis[ii][jj]) && (mp[{i, j}] == 0)) {
    b = 1;
    return;
  }
  vis[ii][jj] = 1;
  mp[{i, j}] = 1;
  dfs(i, j + 1);
  dfs(i, j - 1);
  dfs(i + 1, j);
  dfs(i - 1, j);
}
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;
}
