#include <bits/stdc++.h>
using namespace std;
unsigned int a[1502][1502];
int n, m, sx, sy, nx, ny;
int dy[] = {0, -1, 0, 1}, dx[] = {-1, 0, 1, 0};
bool dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    if (a[((nx % n + n) % n)][((ny % m + m) % m)] > 1 &&
        (397 * (nx + 13) + 491 * ny + 617 * (11 + nx + ny)) !=
            a[((nx % n + n) % n)][((ny % m + m) % m)])
      return true;
    else if (a[((nx % n + n) % n)][((ny % m + m) % m)] == 0) {
      a[((nx % n + n) % n)][((ny % m + m) % m)] =
          (397 * (nx + 13) + 491 * ny + 617 * (11 + nx + ny));
      if (dfs(nx, ny)) return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    char tmp;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> tmp;
        if (tmp == '#')
          a[i][j] = 1;
        else if (tmp == 'S')
          sx = i, sy = j,
          a[sx][sy] = (397 * (sx + 13) + 491 * sy + 617 * (11 + sx + sy));
      }
    }
    if (dfs(sx, sy))
      cout << ("Yes\n");
    else
      cout << ("No\n");
  }
  return 0;
}
