#include <bits/stdc++.h>
using namespace std;
char S[1500 + 10][1500 + 10];
int r, c, cnt = 1;
vector<int> X, Y;
long long visit[1500 + 10][1500 + 10];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int main() {
  int xx = 0, yy = 0;
  scanf("%d%d", &r, &c);
  for (int i = 0; i < r; i++) scanf("%s", S[i]);
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      if (S[i][j] == 'S') {
        xx = i;
        yy = j;
        break;
      }
  X.push_back(xx + 1500 * r);
  Y.push_back(yy + 1500 * c);
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) visit[i][j] = -1;
  while (!X.empty()) {
    int x = X.back(), y = Y.back();
    X.pop_back();
    Y.pop_back();
    if (visit[x % r][y % c] == -1)
      visit[x % r][y % c] = (long long)x * (long long)y;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (visit[nx % r][ny % c] == (long long)nx * (long long)ny)
        continue;
      else if (visit[nx % r][ny % c] >= 0 &&
               visit[nx % r][ny % c] != (long long)nx * (long long)ny) {
        puts("Yes");
        return 0;
      }
      if (S[nx % r][ny % c] == '#') continue;
      X.push_back(nx);
      Y.push_back(ny);
    }
  }
  puts("No");
  return 0;
}
