#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, +1, 0, 0};
int dy[4] = {0, 0, -1, +1};
int n, m;
char a[1500][1500];
pair<int, int> mark[1500][1500];
pair<int, int> dfg = {1000000000, 1000000000};
void dfs(int x, int y) {
  int g, p;
  pair<int, int> ss = {x, y};
  mark[(x % n + n) % n][(y % m + m) % m] = ss;
  pair<int, int> oo;
  for (int i = 0; i < 4; i++) {
    g = x + dx[i];
    p = y + dy[i];
    oo = {g, p};
    if (mark[(g % n + n) % n][(p % m + m) % m] == dfg &&
        a[(g % n + n) % n][(p % m + m) % m] != '#') {
      dfs(g, p);
    }
    if (mark[(g % n + n) % n][(p % m + m) % m] != oo &&
        a[(g % n + n) % n][(p % m + m) % m] != '#') {
      cout << "Yes";
      exit(0);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  int is, js;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      mark[i][j] = {1e9, 1e9};
      if (a[i][j] == 'S') {
        is = i;
        js = j;
      }
    }
  }
  dfs(is, js);
  cout << "No";
}
