#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10000,mod = 80112002;
int dx[4] = {-1,0,0,1};
int dy[4] = {0,1,-1,0};
string s[N];
string tmp[N];
bitset<N> flag[N];
int n,m;
int ans;
void Init(int row,int col){
for(int i = 0;i <= 3 * row + 1;i ++){
for(int j = 0;j <= 3 * col+ 1;j ++){
s[i][j] = 'r';
flag[i][j] = false;
}
}
}
void puts(){
for(int i = 0;i <= 3 * n + 1;i ++){
for(int j = 0;j <= 3 * m + 1;j ++){
cout << s[i][j];
}
cout << "\n";
}
}
void dfs(int x,int y){
if(s[x][y] == 'r'){
ans = 1;
return ;
}
flag[x][y] = true;
for(int i = 0;i < 4;i ++){
if(s[x + dx[i]][y + dy[i]] != '#' && !flag[x + dx[i]][y + dy[i]]){
dfs(x + dx[i],y + dy[i]);
}
}
}
void slove(){
while(cin >> n >> m){
Init(n,m);
int x,y;
for(int i = 1;i <= n;i ++){
cin >> tmp[i];
}
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++){
char ch = tmp[i][j - 1];
s[i + n][j + m] = ch;
s[i][j + m] = ch;
s[i + n][j] = ch;
s[i + n][j + 2 * m] = ch;
s[i + 2 * n][j + m] = ch;
if(ch == 'S'){
x = i + n;
y = j + m;
}
}
}
ans = 0;
dfs(x,y);
if(ans) cout << "Yes" << "\n";
else cout << "No" << "\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while(t--){
slove();
}
return 0;
}