#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18;
long long int n, m, start_x, start_y, f = 0;
vector<string> arr;
vector<vector<long long int>> rec(1501, vector<long long int>(1501, -1));
void dfs(long long int x, long long int y) {
  long long int x1 = (x % n + n) % n;
  long long int y1 = (y % m + m) % m;
  if (rec[x1][y1] != -1 && rec[x1][y1] != x * m + y) {
    f = 1;
  }
  if (rec[x1][y1] != -1) {
    return;
  }
  if (f) {
    return;
  }
  rec[x1][y1] = x * m + y;
  if (arr[((x + 0) % n + n) % n][((y + 1) % m + m) % m] != '#') {
    dfs(x + 0, y + 1);
  }
  if (arr[((x + 1) % n + n) % n][((y + 0) % m + m) % m] != '#') {
    dfs(x + 1, y + 0);
  }
  if (arr[((x - 1) % n + n) % n][((y + 0) % m + m) % m] != '#') {
    dfs(x - 1, y + 0);
  }
  if (arr[((x + 0) % n + n) % n][((y - 1) % m + m) % m] != '#') {
    dfs(x + 0, y - 1);
  }
}
int main(void) {
  cin >> n >> m;
  arr.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 'S') {
        start_x = i, start_y = j;
        break;
      }
    }
  }
  dfs(start_x, start_y);
  cout << (f == 1 ? "Yes" : "No") << endl;
}
