#include <bits/stdc++.h>
using namespace std;
void Fastio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
char arr[2000][2000];
pair<int, int> vis[2000][2000];
int sx, sy, n, m;
bool check(int x, int y) {
  if (arr[(x + 10000 * n) % n][(y + 10000 * m) % m] == '.') return 1;
  return 0;
}
bool st;
int a[] = {0, 0, 1, -1};
int b[] = {1, -1, 0, 0};
void dfs(int x, int y) {
  vis[(x + 10000 * n) % n][(y + 10000 * m) % m] = make_pair(x, y);
  for (int i = 0; i < 4; i++) {
    int nx = (x + a[i]), ny = y + b[i];
    pair<int, int> p(1e9, 1e9), p2(nx, ny);
    if (vis[(nx + 10000 * n) % n][(ny + 10000 * m) % m] != p &&
        vis[(nx + 10000 * n) % n][(ny + 10000 * m) % m] != p2) {
      st = 1;
      return;
    }
    if (vis[(nx + 10000 * n) % n][(ny + 10000 * m) % m] == p && check(nx, ny))
      dfs(nx, ny);
    if (st) return;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'S') sx = i, sy = j;
      vis[i][j] = make_pair(1e9, 1e9);
    }
  }
  st = 0;
  dfs(sx, sy);
  if (st)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
