#include <bits/stdc++.h>
using namespace std;
int n, m;
const int nm = 1500 + 10;
char maze[2000][2000];
pair<int, int> vis[2000][2000];
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
bool isok(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && maze[x][y] != '#');
}
bool bfs(pair<int, int> s) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) vis[i][j] = pair<int, int>(-1, -1);
  queue<pair<int, int> > q;
  q.push(s);
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    int mx = (x % n + n) % n, my = (y % m + m) % m;
    if (vis[mx][my] == pair<int, int>(-1, -1))
      vis[mx][my] = pair<int, int>(x, y);
    else if (vis[mx][my] != pair<int, int>(x, y)) {
      return true;
    } else
      continue;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      mx = (nx % n + n) % n, my = (ny % m + m) % m;
      if (vis[mx][my] != pair<int, int>(nx, ny) && isok(mx, my))
        q.push(pair<int, int>(nx, ny));
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", &maze[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (maze[i][j] == 'S') {
        puts(bfs(pair<int, int>(i, j)) ? "Yes\n" : "No\n");
        break;
      }
    }
  }
  return 0;
}
