#include <bits/stdc++.h>
using namespace std;
const int MAX = 1500 + 10;
const int INF = 1 << 30;
bool g[MAX + 10][MAX + 10];
pair<int, int> mrk[MAX + 10][MAX + 10];
pair<int, int> st;
int n, m;
int movX[4] = {1, -1, 0, 0};
int movY[4] = {0, 0, 1, -1};
void clear() {
  for (int i = 0; i < MAX; i++)
    for (int j = 0; j < MAX; j++) mrk[i][j] = pair<int, int>(INF, INF);
}
bool dfs(int x, int y) {
  if (mrk[(((x) % (n) + (n)) % (n))][(((y) % (m) + (m)) % (m))] !=
      pair<int, int>(INF, INF)) {
    if (x == mrk[(((x) % (n) + (n)) % (n))][(((y) % (m) + (m)) % (m))].first &&
        y == mrk[(((x) % (n) + (n)) % (n))][(((y) % (m) + (m)) % (m))].second) {
      return 0;
    }
    return 1;
  }
  mrk[(((x) % (n) + (n)) % (n))][(((y) % (m) + (m)) % (m))] =
      pair<int, int>(x, y);
  for (int i = 0; i < 4; i++)
    if (!g[(((x + movX[i]) % (n) + (n)) % (n))]
          [(((y + movY[i]) % (m) + (m)) % (m))])
      if (dfs(x + movX[i], y + movY[i])) return 1;
  return 0;
}
int main() {
  clear();
  cin >> n >> m;
  char tmp;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> tmp;
      g[i][j] = (tmp == '#' ? 1 : 0);
      if (tmp == 'S') st = pair<int, int>(i, j);
    }
  if (dfs(st.first, st.second))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  while (cin >> n)
    ;
  return 0;
}
