#include <bits/stdc++.h>
using namespace std;
char a[1510][1510];
int n, m;
pair<int, int> visited[1510][1510];
void dfs_maize(int x, int y) {
  int i = ((x % n) + n) % n;
  int j = ((y % m) + m) % m;
  if (a[i][j] == '#') return;
  if (visited[i][j] == make_pair(x, y)) return;
  if (visited[i][j].first != 2000 && visited[i][j].second != 2000) {
    cout << "YES";
    exit(0);
  }
  visited[i][j] = make_pair(x, y);
  dfs_maize(x - 1, y);
  dfs_maize(x + 1, y);
  dfs_maize(x, y - 1);
  dfs_maize(x, y + 1);
}
void Infinite_Maze_solution() {
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      visited[i][j] = make_pair(2000, 2000);
      if (a[i][j] == 'S') {
        x = i;
        y = j;
      }
    }
  }
  dfs_maize(x, y);
  cout << "NO";
}
int main() {
  Infinite_Maze_solution();
  return 0;
}
