#include <bits/stdc++.h>
using namespace std;
const int INFI = (1 << 30);
const long long INFL = (1LL << 62);
const double eps = 1e-7;
const long double pi = acos(-1.0);
bool a[2000][2000];
int ok[2000][2000][2];
int main() {
  int n, m;
  cin >> n >> m;
  int si, sj;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char ch;
      cin >> ch;
      if (ch == 'S') si = i, sj = j;
      if (ch == '#') a[i][j] = 1;
    }
  si += n * 1000, sj += m * 1000;
  ok[si % n][sj % m][0] = si;
  ok[si % n][sj % m][1] = sj;
  queue<pair<int, int> > q;
  q.push(make_pair(si, sj));
  int v[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    for (int t = 0; t < 4; t++) {
      int vi = i + v[t][0];
      int vj = j + v[t][1];
      int ui = vi % n;
      if (!ui) ui = n;
      int uj = vj % m;
      if (!uj) uj = m;
      if (!a[ui][uj] && !ok[ui][uj][0]) {
        ok[ui][uj][0] = vi;
        ok[ui][uj][1] = vj;
        q.push(make_pair(vi, vj));
      } else if (!a[ui][uj] && ok[ui][uj][0] &&
                 (ok[ui][uj][0] != vi || ok[ui][uj][1] != vj)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}
