#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500 + 10;
int n, m, X, Y;
char a[MAXN][MAXN];
bool vis[MAXN][MAXN];
pair<int, int> fs[MAXN][MAXN];
bool ok = false;
void dfs(int x, int y) {
  if (ok) return;
  int xi = ((x % n) + n) % n, yi = (y % m + m) % m;
  if (vis[xi][yi] && fs[xi][yi] != make_pair(x, y)) ok = true;
  if (a[xi][yi] == '#' || (vis[xi][yi] && fs[xi][yi] == make_pair(x, y)))
    return;
  vis[xi][yi] = true, fs[xi][yi] = {x, y};
  dfs(x - 1, y), dfs(x + 1, y), dfs(x, y - 1), dfs(x, y + 1);
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') X = i, Y = j;
    }
  }
  dfs(X, Y);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
