#include <bits/stdc++.h>
using namespace std;
int n, m;
int mat[1509][1509];
pair<int, int> F[1509][1509];
const int ui[] = {1, -1, 0, 0};
const int uj[] = {0, 0, 1, -1};
int main() {
  scanf("%d %d\n", &n, &m);
  memset(mat, -1, sizeof(mat));
  char ch;
  pair<int, int> start;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%c", &ch);
      if (ch == '#') {
        mat[i][j] = -1;
      } else
        mat[i][j] = 0;
      if (ch == 'S') start = make_pair(i, j);
    }
    scanf("\n");
  }
  bool flag = false;
  F[start.first][start.second] = start;
  mat[start.first][start.second] = 1;
  queue<pair<int, int> > q;
  q.push(start);
  while (!q.empty() && !flag) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    for (int k = 0; k < 4; ++k) {
      int ni = (i + ui[k] + n) % n;
      int nj = (j + uj[k] + m) % m;
      if (mat[ni][nj] == 1) {
        if (F[ni][nj] !=
            make_pair(F[i][j].first + ui[k], F[i][j].second + uj[k]))
          flag = true;
      }
      if (mat[ni][nj] == 0) {
        mat[ni][nj] = 1;
        F[ni][nj] = make_pair(F[i][j].first + ui[k], F[i][j].second + uj[k]);
        q.push(make_pair(ni, nj));
      }
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
