#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e+15;
const long long int mod = 1e9 + 7;
const int MAX = 1505;
int vis[MAX][MAX], n, m, x, y;
pair<int, int> cell[MAX][MAX];
char grid[MAX][MAX];
bool dfs(int x, int y, int xn, int ym) {
  if (grid[xn][ym] == '#') return 0;
  if (vis[xn][ym]) {
    if (x != cell[xn][ym].first or y != cell[xn][ym].second) return 1;
    return 0;
  }
  vis[xn][ym] = 1;
  cell[xn][ym] = make_pair(x, y);
  if (dfs(x + 1, y, (xn + 1) % n, ym) or dfs(x, y + 1, xn, (ym + 1) % m) or
      dfs(x - 1, y, (xn - 1 + n) % n, ym) or
      dfs(x, y - 1, xn, (ym - 1 + m) % m))
    return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == 'S') {
        x = i;
        y = j;
      }
    }
  }
  if (dfs(x, y, x, y))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
