#include <bits/stdc++.h>
using namespace std;
const int N = 15e2 + 10;
int n, m;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
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;
  if (mark[i][j].first < N * N) {
    cout << "Yes\n";
    exit(0);
  }
  mark[i][j] = {x, y};
  for (int k = 0; k < 4; k++) {
    int xx = x + dx[k], yy = y + dy[k];
    dfs(xx, yy);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mp[i][j];
  for (int i = 0; i < N; i++) memset(mark[i], 127, sizeof mark[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mp[i][j] == 'S') dfs(i, j);
  cout << "No\n";
}
