#include <bits/stdc++.h>
using namespace std;
int n, m, S[2];
int num[1505][1505][2];
bool s[1505][1505];
int p[4][2] = {0, -1, 1, 0, 0, 1, -1, 0};
void dfs(int x, int y) {
  if (num[x % n][y % m][0] == -1 && num[x % n][y % m][1] == -1) {
    num[x % n][y % m][0] = x;
    num[x % n][y % m][1] = y;
  } else if (num[x % n][y % m][0] != x || num[x % n][y % m][1] != y) {
    printf("Yes\n");
    exit(0);
  } else
    return;
  for (int i = 0; i < 4; i++) {
    if (s[(x + p[i][0]) % n][(y + p[i][1]) % m]) dfs(x + p[i][0], y + p[i][1]);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  char ch;
  getchar();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ch = getchar();
      if (ch == '.') s[i][j] = true;
      if (ch == 'S') {
        s[i][j] = true;
        S[0] = i + n * m;
        S[1] = j + n * m;
      }
    }
    getchar();
  }
  memset(num, -1, sizeof(num));
  dfs(S[0], S[1]);
  printf("No\n");
  return 0;
}
