#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char s[1555][1555];
int was[1555][1555];
int qx[1555][1555], qy[1555][1555];
int m, n;
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; ++i) scanf("%s", &s[i]);
  queue<pair<int, int> > q;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (s[i][j] == 'S') q.push(make_pair(i, j));
    }
  }
  was[q.front().first][q.front().second] = 1;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    for (int k = 0; k < 4; ++k) {
      int nx = cur.first + dx[k];
      int ny = cur.second + dy[k];
      int ax = qx[cur.first][cur.second];
      int ay = qy[cur.first][cur.second];
      if (nx == -1) nx = m - 1, --ax;
      if (nx == m) nx = 0, ++ax;
      if (ny == -1) ny = n - 1, --ay;
      if (ny == n) ny = 0, ++ay;
      if (s[nx][ny] == '#') continue;
      if (was[nx][ny] && (qx[nx][ny] != ax || qy[nx][ny] != ay)) {
        printf("Yes");
        return 0;
      }
      if (!was[nx][ny]) {
        was[nx][ny] = 1;
        q.push(make_pair(nx, ny));
        qx[nx][ny] = ax;
        qy[nx][ny] = ay;
      }
    }
  }
  printf("No");
  return 0;
}
