#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[1600][1600];
bool vs[1600][1600];
int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};
int plx[1600][1600], ply[1600][1600];
bool dfs(int y, int x, int _ply, int _plx) {
  if (vs[y][x]) {
    if (ply[y][x] != _ply || plx[y][x] != _plx) return true;
    return false;
  }
  vs[y][x] = true;
  ply[y][x] = _ply;
  plx[y][x] = _plx;
  bool res = false;
  for (int i = 0; i < 4; i++) {
    int new_ply = _ply, new_plx = _plx;
    int yy = y + dy[i];
    int xx = x + dx[i];
    if (yy < 0) {
      yy += n;
      new_ply--;
    }
    if (yy >= n) {
      yy -= n;
      new_ply++;
    }
    if (xx < 0) {
      xx += m;
      new_plx--;
    }
    if (xx >= m) {
      xx -= m;
      new_plx++;
    }
    if (str[yy][xx] == '#') continue;
    if (vs[yy][xx] && (ply[yy][xx] != new_ply || plx[yy][xx] != new_plx))
      return true;
    if (!vs[yy][xx]) res |= dfs(yy, xx, new_ply, new_plx);
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", str[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) vs[i][j] = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == 'S') {
        if (dfs(i, j, 0, 0))
          printf("Yes\n");
        else
          printf("No\n");
        return 0;
      }
    }
  }
  return 0;
}
