#include <bits/stdc++.h>
using namespace std;
const int N = 1500 + 10;
int n, m, s1, t1;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
char a[N][N];
pair<int, int> mark[N][N];
void read_input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        s1 = i, t1 = j;
      }
    }
  }
}
void dfs(int x, int y) {
  int i = ((x % n) + n) % n, j = ((y % m) + m) % m;
  if (mark[i][j] == make_pair(x, y) || a[i][j] == '#') return;
  if (mark[i][j] != make_pair(-1, -1)) {
    cout << "Yes\n";
    exit(0);
  }
  mark[i][j] = {x, y};
  for (int k = 0; k < 4; k++) {
    int xx = x + dx[k], yy = y + dy[k];
    dfs(xx, yy);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read_input();
  memset(mark, -1, sizeof mark);
  dfs(s1, t1);
  cout << "No\n";
}
