#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  pair<int, int> res = a;
  res.first += b.first;
  res.second += b.second;
  return res;
}
int main(void) {
  int n, m;
  int sr, sc;
  cin >> n >> m;
  vector<pair<int, int> > steps;
  steps.push_back(make_pair(-1, 0));
  steps.push_back(make_pair(0, -1));
  steps.push_back(make_pair(1, 0));
  steps.push_back(make_pair(0, 1));
  vector<vector<char> > a(n, vector<char>(m, 0));
  vector<vector<pair<int, int> > > v(
      n, vector<pair<int, int> >(
             m, make_pair((-2147483647 - 1), (-2147483647 - 1))));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if ('S' == a[i][j]) {
        sr = i;
        sc = j;
      }
    }
  }
  stack<pair<int, int> > s;
  s.push(make_pair(sr, sc));
  pair<int, int> pos;
  while (!s.empty()) {
    pair<int, int> cell = s.top();
    int r = cell.first;
    int c = cell.second;
    if (r < 0)
      r = (r % n) ? n + (r % n) : 0;
    else if (r >= n)
      r = (r % n);
    if (c < 0)
      c = (c % m) ? m + (c % m) : 0;
    else if (c >= m)
      c = (c % m);
    if (make_pair((-2147483647 - 1), (-2147483647 - 1)) == v[r][c])
      v[r][c] = cell;
    for (int i = 0; i < steps.size(); ++i) {
      pos = cell + steps[i];
      r = pos.first;
      c = pos.second;
      if (r < 0)
        r = (r % n) ? n + (r % n) : 0;
      else if (r >= n)
        r = (r % n);
      if (c < 0)
        c = (c % m) ? m + (c % m) : 0;
      else if (c >= m)
        c = (c % m);
      if (make_pair((-2147483647 - 1), (-2147483647 - 1)) == v[r][c]) {
        if ('#' != a[r][c]) {
          s.push(pos);
          break;
        }
      } else if (pos != v[r][c]) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    if (cell == s.top()) s.pop();
  }
  cout << "No" << endl;
  return 0;
}
