#include <bits/stdc++.h>
using namespace std;
const int N = 1503;
const int M = 1e3 + 502;
const int oo = 1e9;
int mod(int x, int m) {
  if (x < 0) x += N * m;
  return x % m;
}
pair<int, int> mark[N][N], st;
char mx[N][N];
int n, m;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
void dfs(int x, int y) {
  pair<int, int> ctm;
  if ((ctm = mark[mod(x, n)][mod(y, m)]).first != -oo) {
    if (ctm.first != x || ctm.second != y) {
      cout << "Yes" << endl;
      exit(0);
    } else
      return;
  }
  mark[mod(x, n)][mod(y, m)].first = x;
  mark[mod(x, n)][mod(y, m)].second = y;
  for (int(i) = (0); (i) < (4); (i)++) {
    int r = x + dx[i], s = y + dy[i];
    if (mx[mod(r, n)][mod(s, m)] != '#') dfs(r, s);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (int(i) = (0); (i) < (n); (i)++)
    for (int(j) = (0); (j) < (m); (j)++) {
      mark[i][j].first = -oo;
      cin >> mx[i][j];
      if (mx[i][j] == 'S') st = {i, j};
    }
  dfs(st.first, st.second);
  cout << "No" << endl;
  return 0;
}
