#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
char grid[maxn][maxn];
vector<vector<pair<int, int>>> vis(maxn,
                                   vector<pair<int, int>>(maxn, {-1, -1}));
int n, m;
pair<int, int> s;
pair<int, int> dummy = {-1, -1};
int dr[] = {0, 0, -1, 1};
int dc[] = {-1, 1, 0, 0};
int f(int x, int y) {
  x = x % y;
  if (x < 0) x += y;
  return x;
}
bool dfs(pair<int, int> c) {
  int x = f(c.first, n);
  int y = f(c.second, m);
  if (grid[x][y] == '#') return false;
  if (vis[x][y] != dummy) return vis[x][y] != c;
  vis[x][y] = c;
  for (int i = 0; i < 4; ++i) {
    if (dfs({c.first + dr[i], c.second + dc[i]})) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(grid, '#', sizeof grid);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cin >> grid[i][j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == 'S') s = {i, j};
    }
  }
  if (dfs(s))
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
