#include <bits/stdc++.h>
using namespace std;
char m[1505][1505];
bool vst[3003][3003];
int N, M, start_x, start_y;
int d[2][4] = {{-1, 1, 0, 0}, {0, 0, -1, 1}};
bool flag;
void dfs(int i, int j) {
  if (flag) return;
  vst[i][j] = 1;
  if (m[i % N][j % M] == 'S' && (i != start_y || j != start_x)) flag = true;
  for (int k = 0; k < 4; k++) {
    int x = d[0][k] + j;
    int y = d[1][k] + i;
    if (x < 0) x += 2 * M;
    if (y < 0) y += 2 * N;
    if (x >= 2 * M) x -= 2 * M;
    if (y >= 2 * N) y -= 2 * N;
    if (m[y % N][x % M] != '#' && vst[y][x] == 0) {
      dfs(y, x);
    }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      char ch;
      while ((ch = getchar()) != '#' && ch != '.' && ch != 'S')
        ;
      if (ch == 'S') {
        start_x = j;
        start_y = i;
      }
      m[i][j] = ch;
    }
  dfs(start_y, start_x);
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
