#include <bits/stdc++.h>
using namespace std;
const int max_n = 1500;
const int max_m = 1500;
const int inv = numeric_limits<int>::max();
int n, m;
char G[max_n][max_m];
int si, sj;
int di[max_n][max_m][4];
int dj[max_n][max_m][4];
int asz[max_n][max_m] = {0};
int vsti[max_n][max_m];
int vstj[max_n][max_m];
stack<int> sti, stj;
int ct[max_n][max_m] = {0};
bool res;
int amod(int p, int d) {
  if (p % d < 0)
    return p % d + d;
  else
    return p % d;
}
void DFS() {
  int vi, vj;
  sti.push(si);
  stj.push(sj);
  while (!sti.empty()) {
    vi = sti.top();
    vj = stj.top();
    int rvi = amod(vi, n), rvj = amod(vj, m);
    vsti[rvi][rvj] = vi;
    vstj[rvi][rvj] = vj;
    int i;
    int ni, nj, rni, rnj;
    if (ct[rvi][rvj] == asz[rvi][rvj]) {
      sti.pop();
      stj.pop();
    } else {
      i = ct[rvi][rvj];
      ++ct[rvi][rvj];
      ni = vi + di[rvi][rvj][i];
      nj = vj + dj[rvi][rvj][i];
      rni = amod(ni, n);
      rnj = amod(nj, m);
      if (vsti[rni][rnj] == inv) {
        sti.push(ni);
        stj.push(nj);
      } else if (vsti[rni][rnj] != ni or vstj[rni][rnj] != nj) {
        res = true;
        return;
      }
    }
  }
  return;
}
int main() {
  int ldi[4] = {-1, 1, 0, 0};
  int ldj[4] = {0, 0, -1, 1};
  scanf("%d %d", &n, &m);
  char trow[max_m + 10];
  for (int i = 0; i < n; ++i) {
    scanf("%s", trow);
    for (int j = 0; j < m; ++j) {
      G[i][j] = trow[j];
      if (G[i][j] == 'S') {
        G[i][j] = '.';
        si = i;
        sj = j;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (G[i][j] == '.') {
        for (int k = 0; k < 4; ++k) {
          int xi = amod(i + ldi[k], n), xj = amod(j + ldj[k], m);
          if (G[xi][xj] == '.') {
            di[i][j][asz[i][j]] = ldi[k];
            dj[i][j][asz[i][j]] = ldj[k];
            ++asz[i][j];
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      vsti[i][j] = inv;
      vstj[i][j] = inv;
    }
  }
  res = false;
  DFS();
  if (res)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
