#include <bits/stdc++.h>
using namespace std;
int m, n, dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
char mp[1505][1505];
bool flag;
pair<int, int> vis[1505][1505];
void dfs(int x0, int y0) {
  int x = x0 % m, y = y0 % n;
  if (mp[x][y] == '#' || flag || vis[x][y] == pair<int, int>(x0, y0)) return;
  if (vis[x][y] != pair<int, int>(0, 0)) {
    flag = 1;
    return;
  }
  vis[x][y] = pair<int, int>(x0, y0);
  for (int i = 0; i < 4; i++) dfs(x0 + dir[i][0], y0 + dir[i][1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, si, sj;
  scanf("%d%d", &m, &n);
  for (i = 0; i < m; i++) {
    scanf("%s", &mp[i]);
    for (j = 0; j < n; j++) {
      if (mp[i][j] == 'S') si = i, sj = j;
    }
  }
  flag = 0;
  memset(vis, 0, sizeof(vis));
  dfs(si + m * n, sj + m * n);
  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
