#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> board;
int visx[1500][1500], visy[1500][1500];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool dfs(pair<int, int> p, pair<int, int> b) {
  int x = p.first;
  int y = p.second;
  int bx = b.first;
  int by = b.second;
  visx[x][y] = bx;
  visy[x][y] = by;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    int nbx = bx;
    int nby = by;
    if (nx < 0) {
      nbx -= 1;
      nx += n;
    }
    if (ny < 0) {
      nby -= 1;
      ny += m;
    }
    if (nx >= n) {
      nbx += 1;
      nx -= n;
    }
    if (ny >= m) {
      nby += 1;
      ny -= m;
    }
    pair<int, int> np = make_pair(nx, ny);
    pair<int, int> nb = make_pair(nbx, nby);
    if (board[nx][ny] != '#') {
      if (visx[nx][ny] == 2000000000) {
        if (dfs(np, nb)) return true;
      } else if (visx[nx][ny] != nbx || visy[nx][ny] != nby) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  pair<int, int> start;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    board.push_back(s);
    for (int j = 0; j < m; j++) {
      if (s[j] == 'S') start = make_pair(i, j);
    }
  }
  for (int i = 0; i < 1500; i++) {
    for (int j = 0; j < 1500; j++) visx[i][j] = visy[i][j] = 2000000000;
  }
  if (dfs(start, make_pair(0, 0))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
