#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
const int dr[] = {0, 1, 0, -1}, dc[] = {1, 0, -1, 0};
const int MAX = 1507;
int oR, oC, R, C, sr, sc;
char in[MAX][MAX];
bool visited[3 * MAX][3 * MAX];
inline bool check(int r, int c) { return r >= 0 && r < R && c >= 0 && c < C; }
inline int mod(int n, int N) {
  while (n < 0) n += N;
  while (n >= N) n -= N;
  return n;
}
int main() {
  scanf("%d%d", &R, &C);
  for (int i = 0; i < (R); i++) {
    scanf("%s", in[i]);
    for (int j = 0; j < (C); j++) {
      if (in[i][j] == 'S') {
        sr = R + i;
        sc = C + j;
        in[i][j] = '.';
      }
    }
  }
  oR = R;
  oC = C;
  R *= 3;
  C *= 3;
  queue<pair<int, int> > manage;
  manage.push(make_pair(sr, sc));
  visited[sr][sc] = true;
  while (!manage.empty()) {
    int r = manage.front().first, c = manage.front().second;
    manage.pop();
    for (int d = 0; d < (4); d++) {
      int rr = mod(r + dr[d], R), cc = mod(c + dc[d], C);
      if (in[mod(rr, oR)][mod(cc, oC)] == '.' && !visited[rr][cc]) {
        visited[rr][cc] = true;
        manage.push(make_pair(rr, cc));
      }
    }
  }
  bool ok = false;
  for (int r = 0; r < (oR); r++)
    for (int c = 0; c < (oC); c++)
      if (visited[oR + r][oC + c]) {
        for (int a = 0; a < (3); a++)
          for (int b = 0; b < (3); b++) {
            if (a == 1 && b == 1) continue;
            if (visited[a * oR + r][b * oC + c]) ok = true;
          }
      }
  if (ok)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
