#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> mov[4] = {
    make_pair(0, 1), make_pair(1, 0), make_pair(-1, 0), make_pair(0, -1)};
char grid[2000][2000];
pair<long long int, long long int> nodos[2000][2000];
bool vis[2000][2000];
int main() {
  for (long long int i = (long long int)(0); i < (long long int)(2000); i++)
    for (long long int j = (long long int)(0); j < (long long int)(2000); j++)
      vis[i][j] = false;
  long long int n, m;
  long long int xi, yi;
  cin >> n >> m;
  scanf(" ");
  char c;
  for (long long int i = (long long int)(0); i < (long long int)(n); i++) {
    for (long long int j = (long long int)(0); j < (long long int)(m); j++) {
      grid[i][j] = getchar();
      if (grid[i][j] == 'S') {
        grid[i][j] = '.';
        xi = j;
        yi = i;
      }
    }
    scanf(" ");
  }
  stack<pair<long long int, long long int> > pila;
  pila.push(make_pair(xi, yi));
  bool sePuede = false;
  long long int nuevox, nuevoy, realx, realy, nuevorealx, nuevorealy;
  while (!pila.empty()) {
    pair<long long int, long long int> nodo = pila.top();
    pila.pop();
    realx = (nodo.first % m + m) % m;
    realy = (nodo.second % n + n) % n;
    if (!vis[realy][realx]) {
      vis[realy][realx] = true;
      nodos[realy][realx] = make_pair(nodo.first, nodo.second);
      for (long long int i = (long long int)(0); i < (long long int)(4); i++) {
        nuevox = nodo.first + mov[i].first;
        nuevoy = nodo.second + mov[i].second;
        nuevorealx = (nuevox % m + m) % m;
        nuevorealy = (nuevoy % n + n) % n;
        if (grid[nuevorealy][nuevorealx] == '.') {
          pila.push(make_pair(nuevox, nuevoy));
        }
      }
    } else {
      if (nodos[realy][realx].first != nodo.first ||
          nodos[realy][realx].second != nodo.second) {
        sePuede = true;
      }
    }
    if (sePuede) break;
  }
  if (sePuede)
    puts("Yes");
  else
    puts("No");
  return 0;
}
