import java.io.IOException;
import java.util.*;
import java.io.*;
public class Main {
static int n;
static int m;
static BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st =new StreamTokenizer(in);
static boolean res =true;
public static int nextInt() throws IOException {
st.nextToken();
return (int)st.nval;
}
static char[][] cs;
static int [][] directions = {{1,0},{-1,0},{0,1},{0,-1}};
static Scanner scan = new Scanner(System.in);
static HashSet<Integer> set = new HashSet<>();
static HashSet<Integer> isvisited = new HashSet<>();
static boolean[][] isviisted= new boolean[100][100];
public static void main(String[] args) throws IOException {
String line ;
while(scan.hasNext()) {
// String strs[] = line.split(" ");
// n = Integer.parseInt(strs[0]);
// m = Integer.parseInt(strs[1]);
n = scan.nextInt();
m = scan.nextInt();
cs = new char[n][m];
scan.nextLine();
isviisted = new boolean[n][m];
for (int i = 0; i < n; i++) {
String strs2 = scan.nextLine();
cs[i] = strs2.toCharArray();
}
int x = -1;
int y = -1;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
if(cs[i][j]== 'S'){
x = i;
y = j;
}
}
}
dfs(x,y,x,y);
if(res){
System.out.println("No");
}else{
System.out.println("Yes");
}
res = true;
isvisited.clear();
set.clear();
}
// for(int i = 0;i<n;i++){
// if(cs[i][0] == '.'){
//
// }
// if(cs[i][m-1] == '.'){
//
// }
// }
// for(int i =0;i<m;i++){
// if(cs[0][i] == '.'){
//
// }
// if(cs[0][i] == '.'){
//
// }
// }
///
}
public static void dfs(int x, int y,int lx, int ly){
// isviisted[x][y] =true;
// System.out.println(x+" "+ y+" "+lx+" "+ly);
if(set.contains(lx+ly*10000)==true && isvisited.contains(x+y*10000)!=true){
res = false;
return;
}
isvisited.add(x+y*10000);
set.add(lx +ly*10000);
for(int [] dir: directions){
int nx = x + dir[0];
int ny = y + dir[1];
int mx= (lx+dir[0]+n)%(n);
int my = (ly+dir[1]+m)%(m);
if(cs[mx][my] != '#' && (isvisited.contains(nx+ny*10000)!=true ||set.contains(mx+my*10000) != true )){
dfs(nx,ny,mx,my);
}
}
}
}
6 6 ##...# .##..# ..#.S. ..#.#. ..###. ...#.. 12 12 ##.#######.# #..#......S# #.#..####### ..#.###..... ##..##..#### #..##..##### ..##..#..... ###..##.#### ##..#...#### #..##.###### ..##..####.. ##...#####.# 12 12 ###.#.##.#.# ....#.##...# .####.###### .####.###### .####.###### .####.###### .#....###### .#.##.###### .#.##.##S... ##.##.##.### ...##.##.#.. ###...##.#.# 12 12 ######.#.#.# ######.#..S# .......####. ######.####. ............ ############ .....#...... ####.#.##### .....#...... ############ .........#.. ########.#.# 12 12 ######.#.#.# ######.#...# .......####. ######.####. ............ ############ .....#...S.. ####.#.##### .....#...... ############ .........#.. ########.#.# 100 100 ....#.....#...##.....##.##...............###.##....##..##...##........#..#..#.#...#......#.#...#..#. .##....#..#.#..#..#........##...#...##.....#...#.###.#....#...#..##..#.......#...###....##...#...... ..#...#.#....#....#.............#.###....##.......#............#...#........###....#.#..#.....#.#..# ..#..#.........#...#.##.#......#..........#.....#..#...#.#..#...#..#..#..#..........##.#..........## ....#..#................#.#.....##...#......##...#.....................#...#.#.#.......##.......#... ......#.#.#.#.......#.........#..#......#....#..#.......#.#.#..##.#...####....#..#......##.....###.# ..#....#.....#....#...........#.#..####....#.#.......S.........##.#.#...#.#.#..#.....#...#...#...##. ##..#.##.#...#.....##..#..........#...#.......#...#.....#....##.........#...#...#........#.#........ ...#.#.......##.##...#..##........##.....#.#......##...##......#.....#..#.#......#..#............#.# ....#..#....#.#.........#......##............#.....#....##.......#.........#..............##......#. .....#.....#......##.#.#..##.#.#........#...##..#.#...#...........#.#.#....##....#..#..#..##....#... ..............#....#.....#.#..#..#.#...#..#..#.#.......#...#....#....##..........#.#.#..##.......... ##......#...##.#..#........#.#..##..##.#.#.##.......#..#.##.#..#.##.....#.##..###....##..###...#.#.# .#.........#.#............#..#....##..#...#.......#...##............#..#.#.#..#..#.#.##..##...#....# .......#..#.##.......#.....#..#.####....#.....#..##......#....#.#...##.#...#.......#..#...#.#....#.. ...#.##...#..#.##.#.........#####....#.#.......##.#..#.#............#............##....##.......#... ......#......#.#.#....#.....####...#.#....#..#............#.##..........#..#...............#.......# ....#......#.#..........##...##.#....#.##.....#.#.#..#...#..#...............#...#.....#......#..#... .#....###.###.#..#..#.......##....##..#..#............#.#....#...#.#.....#..##..#......#.#...#....#. ...#.#..##.##.....#.#............#...#..#......#.#....#....#...#....##.....#.##.##..#...#......##... .#.#.###.#.....#.#....#................#..#..#..##.....##.............##.....#...#.#..####.#..#.#.## .#..#..##...##.....#......#...#....#.......#.#.#.#...####.............#....#.##..###..#.....#..##.#. ..##...#.....#.......#.#.#..........##.....##......##..#.........###..#.#.##.#.......#...##..#.#.##. ..#..##......#..#...........#....#.#...#...#.#..##..##....#...#...###..#....#..#####...#..#######.## .#...#....##..#...##...#...#..........#...#.###......#..##.#....####.............#....#.....##...... #......#.#...........##...##...#..........##.......#....#.......#.#...##......#.#..#..###...#.#..... .#........##.#.#....#.......##.#.#....#....#...........#.###.#..#.......#...#...###.##...#..#.#...## ...............#.#........#..###....##.....#....##..#...#......#..#....#...#.##.....#..###.....###.. ...#...#...........#.#...#......#........##...#...#..##.#.#.#....#......#........#....#.#.#.#.....#. ..#.##.....#.....#.#.#..#..###.......#........#...#...........#..##...#.#.#.........#...#....#...... #.#.#....#####..##.#.............#.###.#..##.....#......#...##.#.#...###.....##...#.#..#...........# ......#.#........#....##........#..#....#..#..#..#.#....##........##....##..#.......#.........#...#. ..............#.##.....#....#.##.....#.#....#....#...#..##..#..##...###.#..#.....#..........#...#..# .#.#.........##....#.......#...#.....#...##..#..#..##......#..##........#..#.#....#................. ................##.....#.....#........#...##.#.........#.......#.......##..#...##.....#.#...#......# ##..##...##.....#.##..#.....#..#....#......#.......#..........##..#.#.......#...#.....#.#...#..#.### ##.#.....#.#....#..##...#..#...##.##...#.#.##....#.##..#.#.......#....#...####.#.....#..##..#..#.... #......##...#...#......##..#....#....##......#..#.......##...#...#......#.#....#......##.#.#..#.###. #.....#.##...##........#...#.#..##........#....#..#.##....##..##....##...#.........#.#.###...#.#.#.. ...#...#.#.........###.....###...###..###............#......#........#.#........#.##................ .#..###..##....#.#...#......#.#.#.....#..#....#.###.#.#.#..#..#........#..####......#.#....#....#... .........#...............##......#.........#..##......#.#.......#..##...##..#.#..#.........#..#...#. ...................#.......#.#.......#.#......#........##.##....#..#..#.##........#.#.#..#.......... ........#.###....#..##..###.#.....#..##...#....#.#......#.#...#..#..........#.#....#................ .#..###.........##....#...#.....#..###..#...#..#...#..##.#...#.#..##.....#...##..#.#...#...#....##.. ....#.#............#.......#.#....##.#..#.#.##........#.....#....#..#...........#...###..#.......##. .#.##......#.#..........#.#......##...#..#.#..###.#.##....##........#.#.#.#.....#.#.#.###..#........ ..##....#.##...#.##......#.#....#..#..##.........#....##.....#...#....#...........#..#..........#.#. ......#.......#..#.#....#..#......#..#.###.#....#..#..#.......#.#....####..#...#................#..# #..#.#.......#..#..##.........#..........##.#.#...#.#.##...#...#..#.#..#.#...#...#..............##.. #.#.......#...#..#..#......#.#....##.#..##......##...................#.#.......##.#.##..........#.#. ...#......#........#..##....#.....#........#....#........#...#..#...#.##......###.##..##.#.......... #...........#..#......#..#........#....##.......#.........#.#....#..##....#.#..###....#..#...##..#.. ......#....##.#..#...##.#.#.........#.#.#.#......#..#..##.##.#..###..#...#.#....#.........####..#... ##.#...#.#....#.##.#.#..##..#.#......#....#......#.....#.....#.##.....##..#.#...#...#......##......# .#.##.#....#..##.......##...#....#..........#........#....#..............##.....#......#.#..#....... .##....#..........#...#.....#.####.....#.##.#....#...##......#.............#......##.#..#...#....... ..#....#.....#..##.........#..............#.#......#....#.#......####.......#....##................# .#....#.##..#....#.......##.........#.....#.....#..#........#........#.....#..#.#........#.........# ......##.##...#####.#................#..#.....#..#.#......#.#...#....#......#....#.#.#......##...... #.......###...........#.......#........#.#....#...#..#...........#..#..................#..#.#.#..##. ..#.#........#..#.#....#....##...##.##.......#..#.#..#.........###....#......#.###..#....#....##..## .#..#....#........##......##..#..###.#####..#..#....#..####..#...#.......##.#.#................#.... .####...#.....##..##.#..#..#.#.........#..####...#..#....##.#....#....#....#.#...###....#.#......#.. ####.#..#...#........#.###.#...#..#.......#......#..#....#...#......##..##..#......#....#...#..###.. ...#...........###....#..#..........##.##....#.....##.....#..##.#.#..#...#..##..##....#.....#......# #.....##....#.#.#..#..........#....##..##.#...#.....#.#......###.#.....#..#..#............#......... ....#.#......#.##...#..#.......#.#.......#...#.....#####..........#............##.##.#.....#.#..#.#. ..##...............##...#.....##.#..###.#..............##.#.....##.##...#.....#.............#......# .##..#.........#......##..#.....#..#........#.#.........##..##...#....#..#..##..#.........#...#.#.## ......###.#.#......##..#......#...#...#.#.#..#...#...#..#.#.#.#.....#........#.#.#.#.....#..##.##... ...#.#.#..###............#..#...#.....##..#..........#....#....#........#....#.##.###........#..#.#. ..#...###..#......#...#.....#..##.....#..#.#..#..........#.##..##..#.......#.....##.#...#..#....#... #...##.#...#.#..#....##.#..#..........#.#...##..#..........#.#.....#......#.#.......#...#......##... ..##..#.......#....#.###.................#....#......#.#...###.#....#....#...#.#.....##.....#..#.... .##...........##...##..........#.......#..#..##..#.#...##....#...###.............#.....#......#.#... .#..#....##.......#..#.#.##..#.....#....#.#..#..#..##........#....#.###....##..#..#....##........#.. #.#.#.#..##..........#........#.....#...#....#...#..#.###....#.......#....###...#...#....#.#.....#.. .#..#......#.#.#.##....#......#....#.....##..##..#.##....#..#.#...#.....#..#.###.......#..#.....#.#. .....###.....####..##..#..#.#...........#.#.#...#...#.##......#.#....#..#.#.##.....#.#...........### ...#...#..#....#.#...#.........##......#.....##......###..#...##.###....###.#......#.#....##....#... ....#...##..##.....#..........#..#.#.......#.##..#..#.#.....#........#..#.#..#....#.#..........#.#.. ..##.......#...#.#......#.........#....##.#...#....##......#....##..#.....###.#......#.##.#.....#.#. .#...##.#........#.....#.....###..#.#.......##.#.#.#..##...#.#..#....#.....................#..#..... ...#..#.#..#..#..#.....#..#..........##.#.......#....###.......#....#..........#.....#.........###.. ...##....##..#...#.#...........#...#...######...#.....#........#..###..#.....#..##...#.......#...##. ...#..............##...#.#......#..#.....#.##.#..#....#.......#.#.......#..........#......#.#.##.... ##.....#......#.###...#.....#..#.....#.#....#..#...#..#..#....#.#..#..#...#........#.......#..#..... #........##.#...#...........#..##.#.....#.........###.....##.........#..........##....#####......... #....#...#...#...##.#...##........#...#..#.....#..##..........#.#........####........#....#......... ...#.....#.......#...#....#..#.#.#......................#..#......#...#.#.....##........#.....##.... ......#....#...#.##.##....#........#.#.............##...#.....#.#.......#...##.##...#...#..#......## ##...#.#......#.#.#.....#..#.#........#...####..#...#.......#.....#.###..#..#...#.#.......#..#...... .#......#.#.....#.#...#.....###.##..##...##......##....###..##.....##...#.##.#.##...#..#.#...#...... ...#..##..###.#.....#..#....#...##............#.#...##.........#..#....#.......##.#.##...##...##..#. .#.#.#...#...........#.......#......#.##...##.#...##..#.#.#...........##..##.####..#......#......... ..#...#.#...#.#.#........##.#.#.....#..#.#...#..##............#.....#.......#...#..#.....#...#..###. .#..##......#.##...#.##.##.#.#..#.#......#..##......#..#..........##....#...#.#.#..#..###.....#.##.. ......#..#.........#..........##..##.......#....#..##.......#........#........#..............#....#. .....#...###..#...#..##.##..###.#.#...#......#....#........##..#........##.#..#...#.##.#.#...##..... Yes Yes Yes Yes No Yes 本地又能运行?