#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1);
const long long INFF = 1e18;
const int INF = 1e9;
const int mod = 1e9 + 7;
const int MAX = 15e2 + 7;
int n, m;
int sx, sy;
char mp[MAX][MAX];
void init() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%s", mp[i]);
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      if (mp[i][j] == 'S') {
        sx = i, sy = j;
        return;
      }
    }
}
int ck[MAX][MAX];
int xx[] = {0, 1, 0, -1};
int yy[] = {1, 0, -1, 0};
void dfs(int x, int y) {
  for (int i = 0; i < (4); ++i) {
    int nx = x + xx[i];
    int ny = y + yy[i];
    int px = (nx % n + n) % n;
    int py = (ny % m + m) % m;
    if (mp[px][py] == '#') continue;
    if (ck[px][py] == -1) {
      ck[px][py] = nx * m + ny;
      dfs(nx, ny);
    } else if (ck[px][py] == nx * m + ny)
      continue;
    else {
      puts("Yes");
      exit(0);
    }
  }
}
void sol() {
  memset(ck, -1, sizeof(ck));
  ;
  dfs(sx, sy);
  puts("No");
}
int main(void) {
  init();
  sol();
  return 0;
}
