#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
inline int getMod(int up, int base) { return ((up % base) + base) % base; }
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
set<pair<int, int> > done[1502][1502];
int doneCount;
char input[1502][1502];
int row, col, req;
queue<pair<int, int> > Q;
int mx, my;
inline void pushNew(int x, int y) {
  mx = getMod(x, row);
  my = getMod(y, col);
  if (input[mx][my] != '#') {
    if (done[mx][my].find(make_pair(x, y)) == done[mx][my].end()) {
      Q.push(make_pair(x, y));
      done[mx][my].insert(make_pair(x, y));
      doneCount++;
    }
  }
}
int main() {
  doneCount = 0;
  scanf("%d %d", &row, &col);
  req = row * col;
  int i, j;
  int sx = -1, sy = -1;
  for (i = 0; i < row; i++) {
    scanf("%s", input[i]);
    for (j = 0; j < col; j++) {
      if (input[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  }
  pair<int, int> curr;
  int nx, ny, x, y;
  pushNew(sx, sy);
  while (!Q.empty()) {
    curr = Q.front();
    Q.pop();
    x = curr.first;
    y = curr.second;
    if (doneCount > req) {
      break;
    }
    for (i = 0; i < 4; i++) {
      nx = x + dx[i];
      ny = y + dy[i];
      pushNew(nx, ny);
      if (doneCount > req) {
        break;
      }
    }
  }
  if (doneCount > req) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
