#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
char arr[N][N];
int n, m, vis[N][N], p[N][N][2];
int hash_row(int x) { return (x + n * 1500) % n; }
int hash_col(int y) { return (y + m * 1500) % m; }
bool dfs(int ii, int jj) {
  int i = hash_row(ii);
  int j = hash_col(jj);
  if (arr[i][j] == '#') return 0;
  if (vis[i][j]) {
    if (p[i][j][0] != ii || p[i][j][1] != jj) return 1;
    return 0;
  }
  vis[i][j] = true;
  p[i][j][0] = ii;
  p[i][j][1] = jj;
  bool ans = 0;
  for (int k = 0; k < 4; k++) ans |= dfs(ii + dx[k], jj + dy[k]);
  return ans;
}
int main() {
  cin >> n >> m;
  pair<int, int> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'S') s = {i, j};
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) p[i][j][0] = -1, p[i][j][1] = -1;
  }
  if (dfs(s.first, s.second))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
