#include <bits/stdc++.h>
using namespace std;
bool **marked;
string *s;
int n, m;
pair<int, int> p[2010][2010];
inline bool dfs(int x, int y, int nx, int ny, int px = -2, int py = -2) {
  if (marked[x][y] && (p[x][y].first != nx || p[x][y].second != ny))
    return true;
  if (marked[x][y]) return false;
  marked[x][y] = true;
  p[x][y] = {nx, ny};
  for (int i = -1; i < 2; i++)
    for (int j = -1; j < 2; j++) {
      if ((i && j) || (!i && !j)) continue;
      int X = (x + i + n) % n, Y = (y + j + m) % m;
      if (s[X][Y] != '#' && (nx + i != px || ny + j != py))
        if (dfs(X, Y, nx + i, ny + j, nx, ny)) return true;
    }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  s = new string[n];
  marked = new bool *[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) marked[i] = new bool[m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) marked[i][j] = false;
  int X, Y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == 'S') X = i, Y = j;
  if (dfs(X, Y, X, Y))
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
