#include <bits/stdc++.h>
using namespace std;
int inf = 1000 * 1000 * 1000, n, m;
const int MAX = 2000;
int dir[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
char c[MAX][MAX];
pair<int, int> intial(inf, inf);
pair<int, int> mark[MAX][MAX];
inline int domain(int x, int MOD) {
  x = x % MOD;
  x += MOD;
  x = x % MOD;
  return x;
}
void dfs(int x, int y) {
  int xp = domain(x, n), yp = domain(y, m);
  mark[xp][yp] = pair<int, int>(x, y);
  for (register int(i) = int(0); (i) < int(4); ++(i)) {
    int _x = x + dir[i][0], _y = y + dir[i][1];
    int _xp = domain(_x, n), _yp = domain(_y, m);
    if (c[_xp][_yp] == '#') continue;
    if (mark[_xp][_yp] == intial)
      dfs(_x, _y);
    else if (mark[_xp][_yp] != pair<int, int>(_x, _y)) {
      cout << "Yes" << endl;
      exit(0);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (register int(i) = int(0); (i) < int(MAX); ++(i))
    fill(mark[i], mark[i] + MAX, intial);
  pair<int, int> strt;
  for (register int(i) = int(0); (i) < int(n); ++(i))
    for (register int(j) = int(0); (j) < int(m); ++(j)) {
      cin >> c[i][j];
      if (c[i][j] == 'S') strt = pair<int, int>(i, j);
    }
  dfs(strt.first, strt.second);
  cout << "No" << endl;
  return 0;
}
