#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
const int INF = 0x3f3f3f3f;
char str[N][N];
int dp[N][N];
pair<int, int> visit[N][N];
int n, m, dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
bool dfs(int x, int y) {
  int dx = x % n, dy = y % m;
  if (visit[dx][dy] == make_pair(x, y) || str[dx][dy] == '#') return false;
  if (visit[dx][dy] != make_pair(0, 0)) return true;
  visit[dx][dy] = {x, y};
  bool flag = false;
  for (int i = 0; i < 4 && !flag; i++) {
    flag = dfs(x + dir[i][0], y + dir[i][1]);
  }
  return flag;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 0; i < n; i++) {
    scanf("%s", str[i]);
    for (int j = 0; j < m; j++) {
      if (str[i][j] == 'S') {
        x = i, y = j;
      }
    }
  }
  bool flag = dfs(x + n * m, y + n * m);
  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
}
