#include <bits/stdc++.h>
using namespace std;
int n, m, sr, sc;
string v[1507];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
pair<int, int> vis1[1507][1507];
int vis[1507][1507];
void dfs(int x, int y) {
  int nr, nc, tr, tc;
  for (int i = 0; i < 4; i++) {
    nr = (x % n + 2 * n + dx[i]) % n, nc = (y % m + 2 * m + dy[i]) % m,
    tr = x + dx[i], tc = y + dy[i];
    if (v[nr][nc] == '#') continue;
    if (vis[nr][nc]) {
      if (vis1[nr][nc] != make_pair(tr, tc)) {
        cout << "Yes";
        exit(0);
      }
      continue;
    }
    vis1[nr][nc] = {tr, tc};
    vis[nr][nc] = 1;
    dfs(tr, tc);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    for (int j = 0; j < m; j++) {
      if (v[i][j] == 'S') sr = i, sc = j;
    }
  }
  vis[sr][sc] = 1;
  vis1[sr][sc] = {sr, sc};
  dfs(sr, sc);
  cout << "No";
}
int main() {
  solve();
  return 0;
}
