#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 1505;
char matrix[N][N];
int startx, starty;
bool visited[N][N];
pair<int, int> contain[N][N];
bool found;
int dcol[] = {0, 0, -1, 1};
int drow[] = {-1, 1, 0, 0};
inline void input() {
  for (int i = 0; i <= N - 1; ++i) {
    for (int j = 0; j <= N - 1; ++j) {
      matrix[i][j] = 'x';
    }
  }
  cin >> n >> m;
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 0; j <= m - 1; ++j) {
      cin >> matrix[i][j];
      if (matrix[i][j] == 'S') {
        startx = i;
        starty = j;
      }
    }
  }
}
void dfs(int i, int j) {
  if (visited[(i % n + n) % n][(j % m + m) % m]) {
    if (i != contain[(i % n + n) % n][(j % m + m) % m].first ||
        j != contain[(i % n + n) % n][(j % m + m) % m].second) {
      cout << "Yes";
      exit(0);
    } else
      return;
  }
  visited[(i % n + n) % n][(j % m + m) % m] = true;
  contain[(i % n + n) % n][(j % m + m) % m] = {i, j};
  for (int d = 0; d <= 3; ++d) {
    int x = i + drow[d];
    int y = j + dcol[d];
    if (matrix[(x % n + n) % n][(y % m + m) % m] == '.' ||
        matrix[(x % n + n) % n][(y % m + m) % m] == 'S')
      dfs(x, y);
  }
}
void solve() {
  dfs(startx, starty);
  cout << "No";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  solve();
  return 0;
}
