#include <bits/stdc++.h>
using namespace std;
long long C(long long n, long long m) {
  long long result = 1;
  for (int i = 0; i < m; ++i) {
    result *= (n - i);
    result /= (i + 1);
  }
  return result;
}
char arr[1500 + 5][1500 + 5];
int n, m;
int ii, jj;
int mp[2000][2000][2];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
bool dfs(int i, int j) {
  int ni, nj;
  ni = ((i % n) + n) % n;
  nj = ((j % m) + m) % m;
  if (arr[ni][nj] == '#') return 0;
  if (mp[ni][nj][1] != INT_MAX)
    return (mp[ni][nj][1] != j || mp[ni][nj][0] != i ? 1 : 0);
  mp[ni][nj][0] = i;
  mp[ni][nj][1] = j;
  for (int a = 0; a < 4; a++) {
    int nr, nc;
    nr = i + dx[a];
    nc = j + dy[a];
    if (dfs(nr, nc)) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      mp[i][j][1] = INT_MAX;
      if (arr[i][j] == 'S') ii = i, jj = j;
    }
  }
  !dfs(ii, jj) ? cout << "No" : cout << "Yes";
  return 0;
}
