#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1600;
const double PI = 3.14159265358979323846264338;
const double eps = 1e-9;
bool can[N][N];
pair<int, int> used[N][N];
int n, m;
pair<int, int> go[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void ok() {
  puts("Yes");
  exit(0);
}
int md(int x, int q) {
  x %= q;
  x += q;
  return x % q;
}
void dfs(int i, int j) {
  used[md(i, n)][md(j, m)] = {i, j};
  for (auto g : go) {
    int i1 = i + g.first, j1 = j + g.second;
    if (!can[md(i1, n)][md(j1, m)]) continue;
    if (used[md(i1, n)][md(j1, m)].first == 1e9)
      dfs(i1, j1);
    else {
      if (used[md(i1, n)][md(j1, m)].first != i1 ||
          used[md(i1, n)][md(j1, m)].second != j1)
        ok();
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  int x, y;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      used[i][j] = {1e9, 1e9};
      char c;
      cin >> c;
      if (c == 'S') {
        x = i;
        y = j;
      }
      can[i][j] = (c != '#');
    }
  }
  dfs(x, y);
  puts("No");
  return 0;
}
