#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
vector<int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};
int n, m;
string a[N];
bool used[N][N];
int comp[N][N];
void dfs(int x, int y, int c) {
  used[x][y] = true;
  comp[x][y] = c;
  for (int i = 0; i < 4; i++)
    if (x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < m &&
        a[x + dx[i]][y + dy[i]] != '#' && !used[x + dx[i]][y + dy[i]])
      dfs(x + dx[i], y + dy[i], c);
}
vector<pair<int, int> > gx[N * 4], gy[N * 4];
bool check(int n, int s) {
  int d[n], D[n];
  fill(d, d + n, inf);
  fill(D, D + n, -inf);
  d[s] = D[s] = 0;
  for (int t = 0; t < n; t++) {
    bool flag = false;
    for (int u = 0; u < n; u++) {
      if (d[u] == inf || D[u] == -inf) continue;
      for (auto &v : gx[u]) {
        if (d[u] + v.second < d[v.first]) {
          d[v.first] = d[u] + v.second;
          flag = true;
        }
        if (D[u] + v.second > D[v.first]) {
          D[v.first] = D[u] + v.second;
          flag = true;
        }
      }
    }
    if (t == n - 1) return flag;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int c = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if ((i == 0 || i == n - 1 || j == 0 || j == m - 1) && a[i][j] != '#' &&
          !used[i][j])
        dfs(i, j, c++);
  int sx, sy;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
      }
  if (!used[sx][sy]) {
    cout << "No\n";
    return 0;
  }
  for (int x = 0; x < n; x++)
    for (int y = 0; y < m; y++)
      if ((x == 0 || x == n - 1 || y == 0 || y == m - 1) && a[x][y] != '#') {
        for (int i = 0; i < 4; i++)
          if (x + dx[i] < 0 || x + dx[i] >= n || y + dy[i] < 0 ||
              y + dy[i] >= m) {
            int x1 = (x + dx[i] + n) % n, y1 = (y + dy[i] + m) % m;
            if (a[x1][y1] != '#') {
              gx[comp[x][y]].push_back({comp[x1][y1], dx[i]});
              gy[comp[x][y]].push_back({comp[x1][y1], dy[i]});
            }
          }
      }
  if (check(c, comp[sx][sy])) {
    cout << "Yes\n";
    return 0;
  }
  for (int i = 0; i < c; i++) gx[i] = gy[i];
  if (check(c, comp[sx][sy])) {
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  return 0;
}
