#include <bits/stdc++.h>
using namespace std;
void printans(int yes) {
  if (yes)
    printf("Yes\n");
  else
    printf("No\n");
  exit(0);
}
int ast = 150009;
pair<int, int> nvisited = make_pair(ast, ast);
pair<int, int> wall = make_pair(-ast, -ast);
pair<int, int> lab[1509][1509];
pair<int, int> start;
int h, w;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void dfs(int first, int second, pair<int, int> colour) {
  for (int d = 0; d < 4; ++d) {
    int cx = (first + dx[d] + h) / h - 1;
    int cy = (second + dy[d] + w) / w - 1;
    int nx = (first + dx[d] + h) % h;
    int ny = (second + dy[d] + w) % w;
    if (lab[nx][ny] == wall) continue;
    if (lab[nx][ny] == nvisited) {
      lab[nx][ny] = make_pair(colour.first + cx, colour.second + cy);
      dfs(nx, ny, lab[nx][ny]);
    } else {
      if (make_pair(colour.first + cx, colour.second + cy) != lab[nx][ny]) {
        printans(1);
      }
    }
  }
}
int main() {
  scanf("%d%d", &h, &w);
  char tmp;
  scanf("%c", &tmp);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      scanf("%c", &c);
      if (c == '#') {
        lab[i][j] = wall;
        continue;
      }
      if (c == 'S') {
        lab[i][j] = make_pair(0, 0);
        start = make_pair(i, j);
        continue;
      }
      if (c == '.') {
        lab[i][j] = nvisited;
        continue;
      }
      exit(-1);
    }
    scanf("%c", &tmp);
  }
  dfs(start.first, start.second, make_pair(0, 0));
  printans(0);
  return 0;
}
