#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const long long MOD = 1000000000 + 7;
const int MAXN = 1600;
int n, m;
char A[MAXN][MAXN];
int comp[MAXN][MAXN];
inline int mabs(int a) { return a < 0 ? -a : a; }
bool dfsUsed[MAXN][MAXN];
pair<int, int> cell[MAXN][MAXN];
int si, sj;
bool answerYes = false;
void dfs(int ci, int cj) {
  int ti = (ci % n + n) % n;
  int tj = (cj % m + m) % m;
  dfsUsed[ti][tj] = 1;
  cell[ti][tj] = make_pair(ci, cj);
  for (int di = -1; di <= 1; di++)
    for (int dj = -1; dj <= 1; dj++) {
      if (mabs(di + dj) != 1) continue;
      int rcuri = ci + di, rcurj = cj + dj;
      int curi = (ci % n + di + n) % n, curj = (cj % m + dj + m) % m;
      if (dfsUsed[curi][curj] && cell[curi][curj] != make_pair(rcuri, rcurj))
        answerYes = true;
      if (!dfsUsed[curi][curj] && A[curi][curj] != '#') dfs(rcuri, rcurj);
    }
}
void input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
      if (A[i][j] == 'S') si = i, sj = j;
    }
}
int main() {
  input();
  dfs(si, sj);
  if (!answerYes)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
