#include <bits/stdc++.h>
using namespace std;
char c[1502][1502];
bool path[1502][1502];
pair<int, int> stage[1502][1502];
int main(void) {
  int i, j, k;
  int ii, jj;
  int si, sj;
  int sii, sjj;
  int n, m;
  int di[4] = {1, 0, -1, 0};
  int dj[4] = {0, 1, 0, -1};
  string str;
  queue<pair<int, int> > Q;
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> str;
    for (j = 0; j < m; ++j) {
      c[i][j] = str[j];
      path[i][j] = false;
      if (str[j] == 'S') {
        c[i][j] = '.';
        path[i][j] = true;
        Q.push(make_pair(i, j));
        stage[i][j] = make_pair(0, 0);
      }
    }
  }
  for (; !Q.empty(); Q.pop()) {
    i = Q.front().first;
    j = Q.front().second;
    si = stage[i][j].first;
    sj = stage[i][j].second;
    for (k = 0; k < 4; ++k) {
      ii = i + di[k];
      jj = j + dj[k];
      sii = si;
      sjj = sj;
      if (ii < 0) {
        ii = n - 1;
        sii--;
      }
      if (ii >= n) {
        ii = 0;
        sii++;
      }
      if (jj < 0) {
        jj = m - 1;
        sjj--;
      }
      if (jj >= m) {
        jj = 0;
        sjj++;
      }
      if (c[ii][jj] == '#') {
        continue;
      }
      if (!path[ii][jj]) {
        path[ii][jj] = true;
        Q.push(make_pair(ii, jj));
        stage[ii][jj] = make_pair(sii, sjj);
      } else {
        if (stage[ii][jj].first != sii || stage[ii][jj].second != sjj) {
          cout << "YES" << endl;
          return 0;
        }
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
