#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1500 + 5;
char map1[maxn][maxn];
int n, m;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
pair<int, int> vis[maxn][maxn];
pair<int, int> s;
bool bfs() {
  pair<int, int> a, next;
  a = s;
  queue<pair<int, int> > q;
  q.push(a);
  while (!q.empty()) {
    a = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      next.first = a.first + dx[i];
      next.second = a.second + dy[i];
      int tx = (next.first % n + n) % n;
      int ty = (next.second % m + m) % m;
      if (map1[tx][ty] == '#') continue;
      if (vis[tx][ty].first == inf) {
        vis[tx][ty] = next;
        q.push(next);
      } else {
        if (vis[tx][ty].first != next.first ||
            vis[tx][ty].second != next.second)
          return true;
      }
    }
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  bool flag = false;
  for (int i = 0; i < n; i++) {
    scanf("%s", map1[i]);
    if (!flag)
      for (int j = 0; j < m; j++) {
        if (map1[i][j] == 'S') {
          flag = true;
          s = {i, j};
          break;
        }
      }
  }
  memset(vis, inf, sizeof(vis));
  if (bfs()) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}
