#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
const int N = 1505;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int tab[N][N], i, j, n, m, x, y, x2, y2, wspx, wspy, wspx2, wspy2, sx, sy;
char t[N];
pair<int, int> vis[N][N];
queue<pair<pair<int, int>, pair<int, int> > > kol;
pair<pair<int, int>, pair<int, int> > w;
bool good(int a, int b) {
  if (a == n) a = 0;
  if (a == -1) a = n - 1;
  if (b == m) b = 0;
  if (b == -1) b = m - 1;
  return tab[a][b];
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", t);
    for (j = 0; j < m; j++) {
      tab[i][j] = (t[j] == '.');
      vis[i][j] = pair<int, int>(INF, INF);
      if (t[j] == 'S') {
        sx = i;
        sy = j;
        tab[i][j] = 1;
        vis[i][j] = pair<int, int>(0, 0);
      }
    }
  }
  while (!kol.empty()) kol.pop();
  kol.push(pair<pair<int, int>, pair<int, int> >(pair<int, int>(sx, sy),
                                                 pair<int, int>(0, 0)));
  while (!kol.empty()) {
    w = kol.front();
    kol.pop();
    x = w.first.first;
    y = w.first.second;
    wspx = w.second.first;
    wspy = w.second.second;
    for (i = 0; i < 4; i++)
      if (good(x + dx[i], y + dy[i])) {
        x2 = (x + dx[i] + n) % n;
        y2 = (y + dy[i] + m) % m;
        wspx2 = wspx;
        wspy2 = wspy;
        if (dx[i] == 1 && x2 == 0) wspx2++;
        if (dx[i] == -1 && x2 == n - 1) wspx2--;
        if (dy[i] == 1 && y2 == 0) wspy2++;
        if (dy[i] == -1 && y2 == m - 1) wspy2--;
        if (vis[x2][y2] != pair<int, int>(INF, INF) &&
            vis[x2][y2] != pair<int, int>(wspx2, wspy2)) {
          printf("Yes\n");
          return 0;
        }
        if (vis[x2][y2] == pair<int, int>(INF, INF)) {
          vis[x2][y2] = pair<int, int>(wspx2, wspy2);
          kol.push(pair<pair<int, int>, pair<int, int> >(
              pair<int, int>(x2, y2), pair<int, int>(wspx2, wspy2)));
        }
      }
  }
  printf("No\n");
  return 0;
}
