#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int B = 317;
const int N = 1500 + 7;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n, m;
char c[N][N];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool ans = false;
pair<int, int> mm[N][N];
void dfs(int x, int y) {
  mm[(x % n + n) % n][(y % m + m) % m] = {x, y};
  for (int i = 0; i < 4; i++) {
    int xx = ((x % n + n) % n + dx[i] + n) % n;
    int yy = ((y % m + m) % m + dy[i] + m) % m;
    if (c[xx][yy] != '#' && mm[xx][yy] != make_pair(x + dx[i], y + dy[i])) {
      if (mm[xx][yy] != make_pair(inf, inf)) {
        cout << "Yes";
        exit(0);
      } else
        dfs(x + dx[i], y + dy[i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      mm[i][j] = {inf, inf};
      if (c[i][j] == 'S') x = i, y = j;
    }
  }
  dfs(x, y);
  cout << "No";
}
