#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
int i, j;
void solve(void);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
int n, m, a, b;
bool cnt;
bool vis[1501][1501];
char maze[1501][1501];
set<pair<int, int> > s[1501][1501];
int dfs(int x, int y, int ex, int ey, int cntx, int cnty) {
  auto it = s[x][y].find({cntx, cnty});
  if (vis[x][y] == 1 && it != s[x][y].end())
    return 0;
  else if (vis[x][y] == 1)
    return -1;
  vis[x][y] = 1;
  s[x][y].insert({cntx, cnty});
  int val = 0, valx = cntx, valy = cnty;
  if (maze[x][((y - 1) % m + m) % m] != '#' && ((y - 1) % m + m) % m != ey) {
    valx = cntx, valy = cnty;
    if (y - 1 == -1) --valy;
    val = dfs(x, ((y - 1) % m + m) % m, x, y, valx, valy);
  }
  if (val == -1) return val;
  if (maze[x][((y + 1) % m + m) % m] != '#' && ((y + 1) % m + m) % m != ey) {
    valx = cntx, valy = cnty;
    if (y + 1 == m) ++valy;
    val = dfs(x, ((y + 1) % m + m) % m, x, y, valx, valy);
  }
  if (val == -1) return val;
  if (maze[((x - 1) % n + n) % n][y] != '#' && ((x - 1) % n + n) % n != ex) {
    valx = cntx, valy = cnty;
    if (x - 1 == -1) --valx;
    val = dfs(((x - 1) % n + n) % n, y, x, y, valx, valy);
  }
  if (val == -1) return val;
  if (maze[((x + 1) % n + n) % n][y] != '#' && ((x + 1) % n + n) % n != ex) {
    valx = cntx, valy = cnty;
    if (x + 1 == n) ++valx;
    val = dfs(((x + 1) % n + n) % n, y, x, y, valx, valy);
  }
  if (val == -1) return val;
  return 0;
}
void solve() {
  cin >> n >> m;
  for (i = 0; i <= n - 1; ++i)
    for (j = 0; j <= m - 1; ++j) {
      cin >> maze[i][j];
      if (maze[i][j] == 'S') a = i, b = j;
    }
  int val = dfs(a, b, -1, -1, 0, 0);
  if (val == -1)
    cout << "Yes";
  else
    cout << "No";
  cout << "\n";
}
