#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename... t>
using V = vector<t...>;
template <typename t>
void print(ostream& os, const t& a) {
  os << a << '\n';
}
template <typename t, typename... v>
void print(ostream& os, const t& a, v&&... b) {
  os << a << ' ';
  print(os, b...);
}
template <typename t>
void inp(t& a) {
  cin >> a;
}
template <typename t, typename... v>
void inp(t& a, v&... b) {
  cin >> a;
  inp(b...);
}
constexpr int maxn = 1500;
int n, m;
bool tb[maxn][maxn];
pair<int, int> sa, nl = {-1, -1};
pair<int, int> vis[maxn][maxn];
V<pair<int, int> > ilo = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool dfs(pair<int, int> v) {
  vis[((v.first % n) + n) % n][((v.second % m) + m) % m] = v;
  for (auto& q : ilo) {
    pair<int, int> nv = {q.first + v.first, q.second + v.second};
    auto& rf = vis[((nv.first % n) + n) % n][((nv.second % m) + m) % m];
    if (not tb[((nv.first % n) + n) % n][((nv.second % m) + m) % m]) continue;
    if (rf == nl)
      if (dfs(nv)) return true;
    if (rf != nl and rf != nv) {
      ;
      return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  inp(n, m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) vis[i][j] = nl;
  for (int i = 0; i < n; ++i) {
    string s;
    inp(s);
    for (int j = 0; j < m; ++j) {
      tb[i][j] = (s[j] != '#' ? true : false);
      if (s[j] == 'S') sa = {i, j};
    }
  }
  print(cout, dfs(sa) ? "Yes" : "No");
}
