#include <bits/stdc++.h>
using namespace std;
const int N = 1500 + 10;
char t[N][N];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}, n, m;
pair<int, int> mark[N][N], cap;
bool ans = false;
void dfs(int i, int j) {
  int x = ((i % n) + n) % n, y = ((j % m) + m) % m;
  if (t[x][y] == '#') return;
  if (mark[x][y] == pair<int, int>(i, j)) return;
  if (mark[x][y] == pair<int, int>(-1, -1))
    mark[x][y] = pair<int, int>(i, j);
  else {
    cout << "Yes";
    exit(0);
  }
  for (int k = 0; k < 4; k++) dfs(i + dx[k], j + dy[k]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) mark[i][j] = pair<int, int>(-1, -1);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> t[i][j];
      if (t[i][j] == 'S') cap = pair<int, int>(i, j);
    }
  dfs(cap.first, cap.second);
  cout << "No";
}
