#include <bits/stdc++.h>
using namespace std;
struct pnt {
  bool av;
  int x, y;
};
const int MAXN = 1500;
int n, m, nx[MAXN * MAXN], ny[MAXN * MAXN], npl = 0, cx, cy, ux, uy, px, py, gx,
                                            gy;
vector<string> mz(MAXN);
pnt wp[MAXN][MAXN];
bool fnd = false;
int gety(int y) {
  while (y < 0) y += n;
  return y % n;
}
int getx(int x) {
  while (x < 0) x += m;
  return x % m;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++) wp[i][j].av = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> mz[i];
  for (int i = 0; i < n && !npl; i++) {
    for (int j = 0; j < m; j++) {
      if (mz[i][j] == 'S') {
        wp[i][j].y = ny[0] = i;
        wp[i][j].x = nx[0] = j;
        wp[i][j].av = npl = 1;
        break;
      }
    }
  }
  while (npl && !fnd) {
    npl--;
    cx = nx[npl];
    cy = ny[npl];
    for (int i = -1; i <= 1 && !fnd; i++) {
      for (int j = -1; j <= 1 && !fnd; j++) {
        if (1 == abs(i) + abs(j)) {
          uy = cy + i;
          ux = cx + j;
          gy = gety(uy);
          gx = getx(ux);
          if (mz[gy][gx] != '#') {
            if (wp[gy][gx].av) {
              if (wp[gy][gx].x == ux && wp[gy][gx].y == uy)
                continue;
              else {
                fnd = true;
                break;
              }
            } else {
              wp[gy][gx].y = ny[npl] = uy;
              wp[gy][gx].x = nx[npl] = ux;
              wp[gy][gx].av = true;
              npl++;
            }
          }
        }
      }
    }
  }
  cout << (fnd ? "Yes" : "No") << endl;
  return 0;
}
