#include <bits/stdc++.h>
using namespace std;
int n, m, sy, sx, dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
int a[1510][1510];
pair<int, int> vis[1510][1510];
string s;
int mod(int a, int b) {
  if (a < 0) return (a % b + b) % b;
  return a % b;
}
bool dfs(int y, int x) {
  for (int i = 0; i < 4; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    int nxtY = mod(ny, n);
    int nxtX = mod(nx, m);
    if (a[nxtY][nxtX]) continue;
    if (vis[nxtY][nxtX] != make_pair((int)-1e9, (int)-1e9)) {
      if (vis[nxtY][nxtX] != make_pair(ny, nx)) return true;
      continue;
    }
    vis[nxtY][nxtX] = make_pair(ny, nx);
    if (dfs(ny, nx)) return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '#')
        a[i][j] = 1;
      else if (s[j] == 'S')
        sy = i, sx = j;
      vis[i][j] = make_pair((int)-1e9, (int)-1e9);
    }
  }
  vis[sy][sx] = make_pair(sy, sx);
  if (dfs(sy, sx))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
