#include <bits/stdc++.h>
using namespace std;
const int mr[] = {0, 1, 0, -1};
const int mc[] = {1, 0, -1, 0};
char a[1505][1505];
pair<int, int> dp[1505][1505];
int at[1505][1505];
int main() {
  int n, m, sr = 0, sc = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'S') a[sr = i][sc = j] = '.';
  }
  at[sr][sc] = 1;
  dp[sr][sc] = {0, 0};
  queue<pair<int, int> > q;
  for (q.push({sr, sc}); q.size(); q.pop()) {
    tie(sr, sc) = q.front();
    for (int o = 0; o < 4; o++) {
      int tr = sr + mr[o];
      int tc = sc + mc[o];
      int dr = (tr % n + n) % n;
      int dc = (tc % m + m) % m;
      int br = (tr - dr) / n;
      int bc = (tc - dc) / m;
      if (a[dr][dc] == '#') continue;
      if (!at[dr][dc]) {
        at[dr][dc] = 1;
        dp[dr][dc] = {br, bc};
        q.push({tr, tc});
      } else {
        if (dp[dr][dc] != pair<int, int>(br, bc)) return puts("Yes"), 0;
      }
    }
  }
  puts("No");
}
