#include <bits/stdc++.h>
using namespace std;
const int X[4] = {0, 0, 1, -1}, Y[4] = {1, -1, 0, 0};
int n, m, x[2005][2005], y[2005][2005];
bool v[2005][2005];
char mp[2005][2005];
bool dfs(int cx, int cy) {
  int mx = (cx % n + n) % n, my = (cy % m + m) % m;
  if (mp[mx][my] == '#') return 0;
  if (v[mx][my]) return x[mx][my] != cx || y[mx][my] != cy;
  v[mx][my] = 1;
  x[mx][my] = cx, y[mx][my] = cy;
  for (int k = 0; k < 4; k++)
    if (dfs(X[k] + cx, Y[k] + cy)) return 1;
  return 0;
}
void read(char &c) {
  c = getchar();
  while (c != 'S' && c != '.' && c != '#') c = getchar();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mp[i][j] == 'S') printf("%s\n", dfs(i, j) ? "Yes" : "No");
  return 0;
}
