#include <bits/stdc++.h>
using namespace std;
string arr[1501];
int n, m, dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
int pr_x[1501][1501], pr_y[1501][1501];
bool visit[1501][1501];
bool dfs(int x, int y) {
  int mx = (x % n + n) % n, my = (y % m + m) % m;
  if (arr[mx][my] == '#') return false;
  int &px = pr_x[mx][my], &py = pr_y[mx][my];
  if (visit[mx][my]) return px != x || py != y;
  visit[mx][my] = true;
  px = x;
  py = y;
  for (int q = 0; q < 4; ++q)
    if (dfs(x + dx[q], y + dy[q])) return true;
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] == 'S') cout << (dfs(i, j) ? "Yes" : "No");
    }
  }
  return 0;
}
