#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
char ch[1600][1600];
int visit[1600][1600];
const int maxn = 750000;
map<int, bool> was[2000000];
int n, m;
void dfs(int x, int y) {
  if (ch[(x % n + n) % n][(y % m + m) % m] == '#') {
    return;
  }
  if (visit[(x % n + n) % n][(y % m + m) % m] == true) {
    printf("Yes\n");
    exit(0);
  }
  was[x + maxn][y] = true;
  visit[(x % n + n) % n][(y % m + m) % m] = true;
  for (int i = 0; i < 4; i++) {
    if (was[x + dx[i] + maxn][y + dy[i]] == false) {
      dfs(x + dx[i], y + dy[i]);
    }
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  getchar();
  int bx = 0, by = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &ch[i][j]);
      if (ch[i][j] == 'S') {
        bx = i, by = j;
      }
    }
    getchar();
  }
  dfs(bx, by);
  printf("No\n");
  return 0;
}
