#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
pair<int, int> vis[1501][1501];
int n, m;
char g[1501][1501];
void dfs(int x, int y) {
  int u = x % n + n;
  int v = y % m + m;
  u %= n, v %= m;
  if (vis[u][v] == make_pair(x, y) || g[u][v] == '#') return;
  if (vis[u][v] != make_pair(INT_MAX, INT_MAX)) {
    cout << "Yes"
         << "\n";
    exit(0);
  }
  vis[u][v] = {x, y};
  for (int i = 0; i < 4; i++) {
    dfs(x + dx[i], y + dy[i]);
  }
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> g[i][j], vis[i][j] = {INT_MAX, INT_MAX};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == 'S') dfs(i, j);
    }
  }
  cout << "No"
       << "\n";
}
