#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
const int mod = (int)1e9 + 7;
const double eps = 1e-8;
int n, m, k;
char s[1510][1510];
pair<int, int> where[1510][1510];
bool vis[1510][1510];
int d[8] = {-1, 0, 1, 0, 0, -1, 0, 1};
bool bfs(int sx, int sy) {
  queue<pair<int, int> > q;
  vis[sx][sy] = true;
  where[sx][sy] = make_pair(0, 0);
  q.push(make_pair(sx, sy));
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 0; i < 8; i += 2) {
      int tx = x + d[i], ty = y + d[i + 1];
      int dx = where[x][y].first, dy = where[x][y].second;
      if (tx < 1) tx = n, dx--;
      if (tx > n) tx = 1, dx++;
      if (ty < 1) ty = m, dy--;
      if (ty > m) ty = 1, dy++;
      if (s[tx][ty] == '#') continue;
      if (vis[tx][ty]) {
        if (where[tx][ty].first == dx && where[tx][ty].second == dy)
          continue;
        else
          return true;
      } else {
        q.push(make_pair(tx, ty));
        vis[tx][ty] = true;
        where[tx][ty] = make_pair(dx, dy);
      }
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'S') {
        x = i, y = j;
      }
    }
  }
  if (bfs(x, y))
    puts("Yes");
  else
    puts("No");
  return 0;
}
