#include <bits/stdc++.h>
using namespace std;
typedef const char* cstr;
const int oo = (~0u) >> 1;
const long long int ooll = (~0ull) >> 1;
const double inf = 1e+20;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int MOD = 1000000007;
template <typename type>
inline bool cmax(type& a, const type& b) {
  return a < b ? a = b, true : false;
}
template <typename type>
inline bool cmin(type& a, const type& b) {
  return b < a ? a = b, true : false;
}
template <typename type>
inline type sqr(const type& first) {
  return first * first;
}
inline int dbcmp(const double& a, const double& b) {
  return (a > b + eps) - (a < b - eps);
}
inline int sgn(const double& first) { return dbcmp(first, 0); }
template <typename type>
inline type cross(const pair<type, type>& a, const pair<type, type>& b,
                  const pair<type, type>& c) {
  return (b.first - a.first) * (c.second - a.second) -
         (b.second - a.second) * (c.first - a.first);
}
template <typename type>
inline type dot(const pair<type, type>& a, const pair<type, type>& b,
                const pair<type, type>& c) {
  return (b.first - a.first) * (c.first - a.first) +
         (b.second - a.second) * (c.second - a.second);
}
template <typename type>
inline type gcd(type a, type b) {
  if (b)
    while ((a %= b) && (b %= a))
      ;
  return a + b;
}
template <typename type>
inline type lcm(type a, type b) {
  return a * b / gcd(a, b);
}
template <typename type>
inline void bit_inc(vector<type>& st, int first, type inc) {
  while (first < ((int)(st).size())) st[first] += inc, first |= first + 1;
}
template <typename type>
inline type bit_sum(const vector<type>& st, int first) {
  type s = 0;
  while (first >= 0) s += st[first], first = (first & (first + 1)) - 1;
  return s;
}
template <typename type>
inline type bit_kth(const vector<type>& st, int k) {
  int first = 0, second = 0, z = 0;
  while ((1 << (++second)) < ((int)(st).size()))
    ;
  for (int i = (second - 1); i >= 0; --i) {
    if ((first += 1 << i) > ((int)(st).size()) || z + st[first - 1] > k)
      first -= 1 << i;
    else
      z += st[first - 1];
  }
  return first;
}
inline void make_set(vector<int>& set) {
  for (int i = (0); i < (((int)(set).size())); ++i) set[i] = i;
}
inline int find_set(vector<int>& set, int first) {
  int second = first, z;
  while (second != set[second]) second = set[second];
  while (first != set[first]) z = set[first], set[first] = second, first = z;
  return second;
}
inline bool union_set(vector<int>& set, int a, int b) {
  a = find_set(set, a), b = find_set(set, b);
  return a != b ? set[a] = b, true : false;
}
template <typename type>
inline void merge(type& a, type& b) {
  if (((int)(a).size()) < ((int)(b).size())) swap(a, b);
  for (typename type::iterator it = b.begin(); it != b.end(); b.erase(it++))
    a.insert(*it);
}
template <typename type>
inline void merge(priority_queue<type>& a, priority_queue<type>& b) {
  if (((int)(a).size()) < ((int)(b).size())) swap(a, b);
  while (((int)(b).size())) a.push(b.top()), b.pop();
}
struct Initializer {
  Initializer() { ios::sync_with_stdio(false); }
  ~Initializer() { cerr; }
} initializer;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> g(n, string(m, '\0'));
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) cin >> g[i][j];
  pair<pair<int, int>, pair<int, int> > s;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      if (g[i][j] == 'S') s = make_pair(make_pair(i, j), make_pair(0, 0));
  vector<pair<int, int> > d;
  d.push_back(make_pair(1, 0));
  d.push_back(make_pair(0, 1));
  d.push_back(make_pair(0, -1));
  d.push_back(make_pair(-1, 0));
  queue<pair<pair<int, int>, pair<int, int> > > q;
  vector<vector<set<pair<int, int> > > > inq(n,
                                             vector<set<pair<int, int> > >(m));
  q.push(s);
  inq[s.first.first][s.first.second].insert(s.second);
  while (((int)(q).size())) {
    pair<pair<int, int>, pair<int, int> > u = q.front();
    q.pop();
    for (int i = (0); i < (((int)(d).size())); ++i) {
      pair<pair<int, int>, pair<int, int> > v = make_pair(
          make_pair(u.first.first + d[i].first, u.first.second + d[i].second),
          u.second);
      if (v.first.first < 0) v.first.first += n, v.second.first--;
      if (v.first.first >= n) v.first.first -= n, v.second.first++;
      if (v.first.second < 0) v.first.second += m, v.second.second--;
      if (v.first.second >= m) v.first.second -= m, v.second.second++;
      if (g[v.first.first][v.first.second] != '#' &&
          !inq[v.first.first][v.first.second].count(v.second)) {
        q.push(v);
        inq[v.first.first][v.first.second].insert(v.second);
        if (((int)(inq[v.first.first][v.first.second]).size()) > 1)
          return puts("Yes"), 0;
      }
    }
  }
  puts("No");
}
