#include <bits/stdc++.h>
using namespace std;
const int MAX = 1510;
const int MOV[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int N, M;
int si, sj;
char m[MAX][MAX];
bool bio[MAX][MAX];
pair<int, int> pos[MAX][MAX];
void dfs(int i, int j) {
  for (int k = 0; k < (4); ++k) {
    int ii = i + MOV[k][0];
    int jj = j + MOV[k][1];
    int ri = (ii % N + N) % N;
    int rj = (jj % M + M) % M;
    if (m[ri][rj] == '#') continue;
    if (bio[ri][rj]) {
      if (pos[ri][rj] != make_pair(ii, jj)) {
        printf("Yes\n");
        exit(0);
      }
    } else {
      bio[ri][rj] = true;
      pos[ri][rj] = make_pair(ii, jj);
      dfs(ii, jj);
    }
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (N); ++i) {
    scanf("%s", m[i]);
    for (int j = 0; j < (M); ++j)
      if (m[i][j] == 'S') {
        bio[i][j] = true;
        pos[i][j] = make_pair(i, j);
        si = i, sj = j;
      }
  }
  dfs(si, sj);
  printf("No\n");
  return 0;
}
