#include <bits/stdc++.h>
using namespace std;
int n, m;
string st;
int bad[1600][1600];
pair<int, int> was[1600][1600];
int gett(int x, int mod) {
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
pair<int, int> p;
int ans;
pair<int, int> start;
bool cmove(int x, int y) {
  int tx, ty;
  tx = gett(x, n);
  ty = gett(y, m);
  if (bad[tx][ty]) return false;
  return true;
}
void dfs(int x, int y) {
  int tx, ty;
  tx = gett(x, n);
  ty = gett(y, m);
  if (was[tx][ty] != p && was[tx][ty] != make_pair(x, y)) ans = 1;
  if (ans) return;
  if (was[tx][ty] == make_pair(x, y)) return;
  was[tx][ty] = make_pair(x, y);
  if (cmove(x - 1, y)) dfs(x - 1, y);
  if (cmove(x + 1, y)) dfs(x + 1, y);
  if (cmove(x, y - 1)) dfs(x, y - 1);
  if (cmove(x, y + 1)) dfs(x, y + 1);
}
int main() {
  cin.tie(0);
  std ::ios ::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) was[i][j] = make_pair(-1000000, -1000000);
  p = make_pair(-1000000, -1000000);
  for (int i = 0; i < n; i++) {
    cin >> st;
    for (int j = 0; j < m; j++) {
      if (st[j] == '#') bad[i][j] = 1;
      if (st[j] == 'S') start = make_pair(i, j);
    }
  }
  dfs(start.first, start.second);
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
