#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 3000 + 9;
int n, m;
char cell[maxN][maxN];
bool isIn(int r, int c) {
  return (0 <= r) && (r < 2 * n) && (0 <= c) && (c < 2 * m);
}
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
bool visited[maxN][maxN];
void bfs(int sr, int sc) {
  queue<pair<int, int> > que;
  que.push(make_pair(sr, sc));
  visited[sr][sc] = true;
  while (!que.empty()) {
    int r = que.front().first;
    int c = que.front().second;
    que.pop();
    for (int i = 0; i < 4; i++) {
      int rr = (r + dr[i] + 2 * n) % (2 * n);
      int cc = (c + dc[i] + 2 * m) % (2 * m);
      if (!isIn(rr, cc)) {
        continue;
      }
      if (visited[rr][cc]) {
        continue;
      }
      if (cell[rr][cc] == '#') {
        continue;
      }
      visited[rr][cc] = true;
      que.push(make_pair(rr, cc));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> cell[i];
  }
  int sR = -1, sC = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char to = (cell[i][j] == 'S') ? '.' : cell[i][j];
      if (cell[i][j] == 'S') {
        sR = i;
        sC = j;
      }
      cell[i][j + m] = to;
      cell[i + n][j] = to;
      cell[i + n][j + m] = to;
    }
  }
  bfs(sR, sC);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (visited[i][j] && visited[i + n][j]) {
        cout << "Yes\n";
        return 0;
      }
      if (visited[i][j] && visited[i][j + m]) {
        cout << "Yes\n";
        return 0;
      }
      if (visited[i][j] && visited[i + n][j + m]) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}
