#include <bits/stdc++.h>
using namespace std;
const int M = 1500 + 5, inf = 1e9 + 7;
int n, m;
pair<int, int> mark[M][M];
bool A[M][M];
inline int state(int i, int j) { return (i * M + j); }
void dfs(int i, int j, int i2, int j2) {
  i = (i % n + n) % n, j = (j % m + m) % m;
  if (!A[i][j]) return;
  if (mark[i][j] == make_pair(i2, j2)) return;
  if (mark[i][j].first < inf && mark[i][j] != make_pair(i2, j2)) {
    cout << "Yes\n";
    exit(0);
  }
  mark[i][j] = make_pair(i2, j2);
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  for (int k = 0; k < 4; k++) dfs(i + dx[k], j + dy[k], i2 + dx[k], j2 + dy[k]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++) mark[i][j] = make_pair(inf + 1, inf + 1);
  int root;
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++)
      if (s[j] != '#') {
        A[i][j] = 1;
        if (s[j] == 'S') root = state(i, j);
      }
  }
  dfs(root / M, root % M, root / M, root % M);
  cout << "No\n";
  return 0;
}
