#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int INF = 0x3fffffff;
const double EPS = 1e-9;
const double PI = 2 * asin(1);
int g_xn, g_yn;
int g_xu, g_yu;
vector<string> vs;
vector<vector<vector<int>>> vvvi;
vector<vector<bool>> vvb_mark;
const int dx[]{0, 1, 0, -1};
const int dy[]{1, 0, -1, 0};
void pretreat() {}
bool input() {
  cin >> g_xn >> g_yn;
  if (cin.eof()) return false;
  vs.clear(), vvvi.clear(), vvb_mark.clear();
  vvb_mark.resize(g_xn), vvvi.resize(g_xn);
  string s;
  for (int i = 0; i < g_xn; ++i) {
    vvb_mark[i].resize(g_yn);
    vvvi[i].resize(g_yn);
    cin >> s;
    vs.push_back(s);
    for (int j = 0; j < g_yn; ++j) {
      vvvi[i][j].resize(2);
      if (s[j] == 'S') {
        g_xu = i, g_yu = j;
      }
    }
  }
  return true;
}
void dfs(int x, int y) {
  for (int i = 0; i < 4; ++i) {
    int xn = x + dx[i], yn = y + dy[i];
    int xm = (xn % g_xn + g_xn) % g_xn, ym = (yn % g_yn + g_yn) % g_yn;
    if (vs[xm][ym] == '#') continue;
    if (vvb_mark[xm][ym]) {
      if (xn != vvvi[xm][ym][0] || yn != vvvi[xm][ym][1]) {
        puts("Yes");
        exit(0);
      }
    } else {
      vvb_mark[xm][ym] = true;
      vvvi[xm][ym][0] = xn;
      vvvi[xm][ym][1] = yn;
      dfs(xn, yn);
    }
  }
}
void solve() {
  dfs(g_xu, g_yu);
  puts("No");
}
int main() {
  pretreat();
  input();
  solve();
  return 0;
}
