#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int n, m;
pair<int, int> start;
char a[MAXN][MAXN];
bool vis[MAXN][MAXN];
pair<int, int> sm[MAXN][MAXN];
bool dfs(int x, int y, pair<int, int> shift) {
  if (vis[x][y]) {
    return !(sm[x][y] == shift);
  }
  vis[x][y] = true;
  sm[x][y] = shift;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    pair<int, int> nshift = shift;
    if (nx >= n) {
      nx = 0;
      nshift.first++;
    }
    if (ny >= m) {
      ny = 0;
      nshift.second++;
    }
    if (nx < 0) {
      nx = n - 1;
      nshift.first--;
    }
    if (ny < 0) {
      ny = m - 1;
      nshift.second--;
    }
    if (a[nx][ny] != '#')
      if (dfs(nx, ny, nshift)) return true;
  }
  return false;
}
int main() {
  scanf("%d %d%*c", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &a[i][j]);
      if (a[i][j] == 'S') start.first = i, start.second = j;
    }
    scanf("\n");
  }
  if (dfs(start.first, start.second, pair<int, int>(0, 0)))
    printf("Yes");
  else
    printf("No");
  return 0;
}
