#include <bits/stdc++.h>
using namespace std;
char ma[1600][1600];
int vis[1600][1600];
pair<int, int> p[1600][1600];
pair<int, int> b[1600][1600];
int n, m;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int _x = -1, _y = -1;
int c = 1;
void dfs(int u, int v, int xx, int yy) {
  vis[u][v] = c++;
  b[u][v] = make_pair(xx, yy);
  for (int i = 0; i < 4; i++) {
    int X = (u + dx[i] + n) % n;
    int Y = (v + dy[i] + m) % m;
    int _xx = xx;
    int _yy = yy;
    if (i == 0 && u == n - 1) _xx++;
    if (i == 1 && u == 0) _xx--;
    if (i == 2 && v == m - 1) _yy++;
    if (i == 3 && v == 0) _yy--;
    if (vis[X][Y] && (p[u][v].first != X || p[u][v].second != Y) &&
        vis[X][Y] < vis[u][v] &&
        (_xx != b[X][Y].first || _yy != b[X][Y].second)) {
      cout << "Yes";
      exit(0);
    }
    if (ma[X][Y] == '#' || vis[X][Y]) continue;
    p[X][Y] = make_pair(u, v);
    dfs(X, Y, _xx, _yy);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", ma[i]);
  if (n == 1 || m == 1) {
    cout << "Yes";
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (ma[i][j] == 'S') {
        _x = i;
        _y = j;
      }
  if (n == 2 && m == 2) {
    bool f = 0;
    for (int i = 0; i < 4; i++) {
      int X = (_x + dx[i] + n) % n;
      int Y = (_y + dy[i] + m) % m;
      if (ma[X][Y] == '.') f = 1;
      if (f) {
        cout << "Yes";
        return 0;
      }
    }
  }
  p[_x][_y] = make_pair(-1, -1);
  dfs(_x, _y, 0, 0);
  cout << "No";
}
