#include <bits/stdc++.h>
using namespace std;
const int N = 15e2 + 10;
int n, m, xx, yy, cnt;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
char mp[N][N];
pair<int, int> mark[N][N];
void dfs(int x, int y) {
  int i = ((x % n) + n) % n, j = ((y % m) + m) % m;
  if (mark[i][j] == pair<int, int>(x, y) || mp[i][j] == '#') return;
  mark[i][j] = {x, y};
  cnt++;
  if (cnt > n * m) {
    cout << "Yes";
    exit(0);
  }
  for (int k = 0; k < 4; k++) {
    int nx = x + dx[k], ny = y + dy[k];
    dfs(nx, ny);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> mp[i][j];
      if (mp[i][j] == 'S') xx = i, yy = j;
    }
  for (int i = 0; i < N; i++)
    fill(mark[i], mark[i] + N, pair<int, int>(1e9 + 10, 1e9 + 10));
  dfs(xx, yy);
  cout << "No";
}
