#include <bits/stdc++.h>
using namespace std;
int inSize(int c, int x, int y) {
  if (c >= x && c <= y) return true;
  return false;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int maxn = 1505;
char mp[maxn][maxn];
int n, m, rear, front;
pair<int, int> que[maxn * maxn];
pair<int, int> pp[maxn][maxn];
bool bo[maxn][maxn];
int main() {
  memset(bo, false, sizeof(bo));
  rear = front = 0;
  scanf("%d", &(n));
  scanf("%d", &(m));
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%s", &mp[i][1]);
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (1); (j) <= (m); (j)++)
      if (mp[i][j] == 'S') {
        que[rear].first = i;
        que[rear++].second = j;
        bo[i][j] = true;
        pp[i][j].first = pp[i][j].second = 0;
      }
  while (front < rear) {
    for (int i = 0; i < 4; i++) {
      int tx = que[front].first + dx[i];
      int ty = que[front].second + dy[i];
      int xp = pp[que[front].first][que[front].second].first;
      int yp = pp[que[front].first][que[front].second].second;
      if (tx == 0) {
        tx = n;
        xp++;
      }
      if (tx == n + 1) {
        tx = 1;
        xp--;
      }
      if (ty == 0) {
        ty = m;
        yp++;
      }
      if (ty == m + 1) {
        ty = 1;
        yp--;
      }
      if (!bo[tx][ty]) {
        if (mp[tx][ty] != '#') {
          que[rear].first = tx;
          que[rear++].second = ty;
          bo[tx][ty] = true;
          pp[tx][ty].first = xp;
          pp[tx][ty].second = yp;
        }
      } else {
        if (xp != pp[tx][ty].first || yp != pp[tx][ty].second) {
          puts("Yes");
          return 0;
        }
      }
    }
    front++;
  }
  puts("No");
  return 0;
}
