#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> S;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char input[2020][2020];
bool vis[2020][2020];
pair<int, int> origem[2020][2020];
inline int first(int a, int b) {
  int ret = a % b;
  if (ret < 0) ret += b;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> input[i][j];
      if (input[i][j] == 'S') {
        input[i][j] = '.';
        S = make_pair(i, j);
      }
    }
  }
  queue<pair<int, int> > q;
  q.push(make_pair(S.first, S.second));
  vis[S.first][S.second] = true;
  origem[S.first][S.second] = make_pair(S.first, S.second);
  while (!q.empty()) {
    int lin = q.front().first;
    int col = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nlin = lin + dx[i];
      int ncol = col + dy[i];
      if (input[first(nlin, n)][first(ncol, m)] == '#') continue;
      if (!vis[first(nlin, n)][first(ncol, m)]) {
        vis[first(nlin, n)][first(ncol, m)] = true;
        origem[first(nlin, n)][first(ncol, m)] = make_pair(nlin, ncol);
        q.push(make_pair(nlin, ncol));
      } else {
        if (origem[first(nlin, n)][first(ncol, m)] != make_pair(nlin, ncol)) {
          cout << "Yes\n";
          return 0;
        }
      }
    }
  }
  cout << "No\n";
  return 0;
}
