#include <bits/stdc++.h>
using namespace std;
bool vis[1500][1500], a[1500][1500];
unordered_map<int, unordered_map<int, bool>> visit;
bool f = 0;
void dfs(int i, int j, int n, int m) {
  if (f == 1) {
    return;
  }
  if (a[(i + 10000 * n) % n][(j + 10000 * m) % m] == 0) {
    return;
  }
  if (visit[i].count(j)) {
    return;
  }
  visit[i][j] = 1;
  if (vis[(i + 10000 * n) % n][(j + 10000 * m) % m]) {
    f = 1;
    return;
  }
  vis[(i + 10000 * n) % n][(j + 10000 * m) % m] = 1;
  dfs(i + 1, j, n, m);
  dfs(i - 1, j, n, m);
  dfs(i, j + 1, n, m);
  dfs(i, j - 1, n, m);
}
int main() {
  int i, j, m, z, k, t, q, x1, n, y1, j1, j2;
  scanf("%d%d", &n, &m);
  char c;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf(" %c", &c);
      if (c == '.' || c == 'S') {
        a[i][j] = 1;
      }
      if (c == 'S') {
        x1 = i, y1 = j;
      }
    }
  }
  dfs(x1, y1, n, m);
  if (f) {
    cout << "Yes" << endl;
    ;
  } else {
    cout << "No" << endl;
    ;
  }
}
