#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const vector<pair<int, int>> dir = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
const int N = 1501;
pair<int, int> vis[N][N];
vector<string> mat;
int n, m;
void dfs(int i, int j) {
  vis[(i % n + n) % n][(j % m + m) % m] = {i, j};
  for (auto k : dir) {
    int ii = i + k.first;
    int jj = j + k.second;
    if (mat[(ii % n + n) % n][(jj % m + m) % m] == '#') continue;
    if (vis[(ii % n + n) % n][(jj % m + m) % m] == make_pair(-INF, -INF))
      dfs(ii, jj);
    else if (vis[(ii % n + n) % n][(jj % m + m) % m] != make_pair(ii, jj)) {
      cout << "YES\n";
      exit(0);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      vis[i][j] = {-INF, -INF};
    }
  }
  mat.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == 'S') {
        dfs(i, j);
        cout << "NO\n";
        return 0;
      }
    }
  }
}
