#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &t, T f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
  if (t < f) t = f;
}
const int INF = 2147483647 / 3;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
int n, m;
string str[1510];
int mem[1510][1510][2];
int main() {
  for (int i = 0; i < (1510); ++i)
    for (int j = 0; j < (1510); ++j) mem[i][j][0] = mem[i][j][1] = INF;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> str[i];
  int x, y;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j)
      if (str[i][j] == 'S') {
        y = i;
        x = j;
        goto aaa;
      }
aaa:;
  queue<pair<int, int> > que;
  que.push(make_pair(y, x));
  bool ok = false;
  mem[y][x][0] = y;
  mem[y][x][1] = x;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < (4); ++i) {
      int ny = ((p.first + dy[i]) % n + n) % n;
      int nx = ((p.second + dx[i]) % m + m) % m;
      if (str[ny][nx] == '#') continue;
      pair<int, int> next = make_pair(p.first + dy[i], p.second + dx[i]);
      if (mem[ny][nx][0] != INF) {
        if (mem[ny][nx][0] != next.first || mem[ny][nx][1] != next.second) {
          ok = true;
          break;
        }
      } else {
        mem[ny][nx][0] = next.first;
        mem[ny][nx][1] = next.second;
        que.push(next);
      }
    }
    if (ok) break;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}
