#include <bits/stdc++.h>
using namespace std;
template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) {
  a = max(a, b);
}
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) {
  a = min(a, b);
}
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
  num_t res = 1;
  for (; k; k >>= 1) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
  }
  return res;
}
const int inf = 1e9 + 7;
const long long ll_inf = 1ll * inf * inf;
const int MAX_N = 1500 + 7;
const int mod = inf;
int n, m;
string s[MAX_N];
bitset<MAX_N * 2> check[MAX_N * 2];
int x[4] = {0, 0, -1, 1};
int y[4] = {-1, 1, 0, 0};
void solve() {
  cin >> n >> m;
  pair<int, int> root = {-1, -1};
  for (int i = (0), _b = (n); i < _b; ++i) {
    cin >> s[i];
    for (int j = (0), _b = (m); j < _b; ++j)
      if (s[i][j] == 'S') root = {i, j};
  }
  static pair<int, int> queue_[MAX_N * MAX_N * 4];
  int top = 0;
  queue_[top++] = root;
  check[root.first][root.second] = true;
  for (int j = 0; j < top; ++j) {
    int u = queue_[j].first;
    int v = queue_[j].second;
    for (int j = (0), _b = (4); j < _b; ++j) {
      int new_u = u + x[j];
      int new_v = v + y[j];
      addmod(new_u, 0, n * 2);
      addmod(new_v, 0, m * 2);
      int ori_u = new_u;
      addmod(ori_u, 0, n);
      int ori_v = new_v;
      addmod(ori_v, 0, m);
      if (s[ori_u][ori_v] != '#' && !check[new_u][new_v]) {
        check[new_u][new_v] = true;
        queue_[top++] = {new_u, new_v};
      }
    }
  }
  if (check[root.first][root.second + m] ||
      check[root.first + n][root.second + m] ||
      check[root.first + n][root.second]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
