#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1550;
int m, n;
char a[maxn][maxn];
int vis[maxn][maxn];
int rootx, rooty;
int way[5][2] = {{0, 0}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int pas[5] = {0, 2, 1, 4, 3};
int pst[maxn][maxn];
void ok() {
  cout << "Yes";
  exit(0);
}
void dfs(int x, int y, int wway, int poipic) {
  int i;
  vis[x][y] = 1;
  pst[x][y] = poipic;
  for (i = 1; i <= 4; ++i) {
    if (pas[i] == wway) continue;
    int newpoi = poipic;
    int nowx = x + way[i][0];
    int nowy = y + way[i][1];
    if (nowx >= n) {
      nowx = 0;
      newpoi += 20;
    } else if (nowx < 0) {
      nowx = n - 1;
      newpoi -= 20;
    } else if (nowy >= m) {
      nowy = 0;
      newpoi++;
    } else if (nowy < 0) {
      nowy = m - 1;
      newpoi--;
    }
    if (a[nowx][nowy] == '#') continue;
    if (vis[nowx][nowy]) {
      if (newpoi != pst[nowx][nowy]) ok();
    } else
      dfs(nowx, nowy, i, newpoi);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j, k;
  cin >> n >> m;
  for (i = 0; i <= n - 1; ++i) cin >> a[i];
  for (i = 0; i <= n - 1; ++i) {
    for (j = 0; j <= m - 1; ++j) {
      if (a[i][j] == 'S') {
        rootx = i, rooty = j;
        goto ret;
      }
    }
  }
ret:
  dfs(rootx, rooty, 0, 210);
  cout << "No";
  return 0;
}
