#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> grid;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void dfs(int x, int y) {
  if (grid[x][y] == '#' || grid[x][y] == '1') return;
  if (grid[x][y] == 'S') {
    cout << "Yes";
    exit(0);
  }
  grid[x][y] = '1';
  for (int i = 0; i < 4; i++) {
    dfs(((x + dx[i]) + n) % n, ((y + dy[i]) + m) % m);
  }
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  string s;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      if (s[j] == 'S') x = i, y = j;
    s += s;
    grid.push_back(s);
  }
  for (int i = 0; i < n; i++) grid.push_back(grid[i]);
  grid[x][y] = '.';
  n *= 2;
  m *= 2;
  dfs(x, y);
  cout << "No";
  return 0;
}
