We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (x, y) is a wall if and only if cell <image> is a wall.

In this problem <image> is a remainder of dividing number a by number b.

The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell (x, y) he can go to one of the following cells: (x, y - 1), (x, y + 1), (x - 1, y) and (x + 1, y), provided that the cell he goes to is not a wall.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1500) — the height and the width of the maze that the boy used to cyclically tile the plane.

Each of the next n lines contains m characters — the description of the labyrinth. Each character is either a "#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point. 

The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input.

Output

Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes).

Examples

Input

5 4
##.#
##S#
#..#
#.##
#..#


Output

Yes


Input

5 4
##.#
##S#
#..#
..#.
#.##


Output

No

Note

In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.

In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the maze traps the boy.
import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	StreamTokenizer in;
	BufferedReader reader;
	PrintWriter out;
	StringTokenizer tok;
	Scanner sc;
	boolean timus = System.getProperty("ONLINE_JUDGE") != null;
	boolean codeforces = true;
	final double eps = 1e-9;

	public static void main(String[] args) throws Exception {
		new Thread(new Solution()).start();
	}

	@Override
	public void run() {
		try {
			if (codeforces) {
				sc = new Scanner(System.in);
				reader = new BufferedReader(new InputStreamReader(System.in));
				in = new StreamTokenizer(reader);
				out = new PrintWriter(new OutputStreamWriter(System.out));
				tok = new StringTokenizer("");
				solve();
				out.flush();
			} else if (timus) {
				sc = new Scanner("input.txt");
				reader = new BufferedReader(new FileReader("input.txt"));
				in = new StreamTokenizer(reader);
				out = new PrintWriter(new FileWriter("output.txt"));
				tok = new StringTokenizer("");
				solve();
				out.flush();
				out.close();
			} else if (!timus) {
				long begMem = Runtime.getRuntime().totalMemory()
						- Runtime.getRuntime().freeMemory();
				long t1 = System.currentTimeMillis();
				reader = new BufferedReader(new InputStreamReader(System.in));
				in = new StreamTokenizer(reader);
				sc = new Scanner(System.in);
				out = new PrintWriter(new OutputStreamWriter(System.out));
				tok = new StringTokenizer("");
				solve();
				long endMem = Runtime.getRuntime().totalMemory()
						- Runtime.getRuntime().freeMemory();
				out.flush();
				long t2 = System.currentTimeMillis();
				System.out.println("Time:" + (t2 - t1));
				System.out.println("Memory:" + (endMem - begMem));
				System.out.println("Total memory: "
						+ (Runtime.getRuntime().totalMemory() - Runtime
								.getRuntime().freeMemory()));
			}
		} catch (Exception ex) {
			System.out.println("fail");
			System.exit(1);
		}
	}

	public class Chess {
		String coord;

		public Chess(String s) {
			this.coord = s;
		}

		public int toInteger(char s) {
			if (s == 'a' || s == 'A')
				return 1;
			else if (s == 'b' || s == 'B')
				return 2;
			else if (s == 'c' || s == 'C')
				return 3;
			else if (s == 'd' || s == 'D')
				return 4;
			else if (s == 'e' || s == 'E')
				return 5;
			else if (s == 'f' || s == 'F')
				return 6;
			else if (s == 'g' || s == 'G')
				return 7;
			else if (s == 'h' || s == 'H')
				return 8;
			else
				return -1;
		}

		public String toString(int s) {
			if (s == 1)
				return "a";
			else if (s == 2)
				return "b";
			else if (s == 3)
				return "c";
			else if (s == 4)
				return "d";
			else if (s == 5)
				return "e";
			else if (s == 6)
				return "f";
			else if (s == 7)
				return "g";
			else if (s == 8)
				return "h";
			else
				return "0";
		}

		public pair getPair() {
			String j = "";
			j += coord.charAt(1);
			pair p = new pair(toInteger(coord.charAt(0)), Integer.parseInt(j));
			if (p.x != -1)
				return p;
			else
				return new pair(0, 0);
		}

		public String returnPair(pair p) {
			return toString(p.x) + p.y;
		}
	}

	public int nextInt() throws Exception {
		in.nextToken();
		return (int) in.nval;
	}

	public String next() throws Exception {
		in.nextToken();
		return in.sval;
	}

	public String nextLine() throws Exception {
		return reader.readLine();
	}

	public String nextString() throws Exception {
		while (!tok.hasMoreTokens())
			tok = new StringTokenizer(reader.readLine());
		return tok.nextToken();
	}

	public long nextLong() throws Exception {
		return Long.parseLong(nextString());
	}

	public double nextDouble() throws Exception {
		in.nextToken();
		return in.nval;
	}

	public class pair {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	public int gcd(int a, int b) {
		if (a == 0 || b == 0)
			return 1;
		if (a < b) {
			int c = b;
			b = a;
			a = c;
		}
		while (a % b != 0) {
			a = a % b;
			if (a < b) {
				int c = b;
				b = a;
				a = c;
			}
		}
		return b;
	}

	public int pow(int a, int n) {
		if (n == 0)
			return 1;
		int k = n, b = 1, c = a;
		while (k != 0) {
			if (k % 2 == 0) {
				k /= 2;
				c *= c;
			} else {
				k--;
				b *= c;
			}
		}
		return b;
	}

	public int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	public class pairs implements Comparable<pairs> {
		int x;
		int y;

		public pairs(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(pairs obj) {
			if (this.x < ((pairs) obj).x)
				return 1;
			else if (this.x == (obj).x && this.y < (obj).y)
				return 1;
			else if (this.x == (obj).x && this.y == (obj).y)
				return 0;
			else
				return -1;
		}
	}

	public class Graf {

		int[][] a;
		int[] colors;
		ArrayList<String> points = new ArrayList<String>();
		LinkedList<Integer> queue = new LinkedList<Integer>();
		boolean[] used;
		boolean cycle;
		int numberOfCycle;

		public Graf(int[][] a, String s[]) {
			this.a = new int[s.length][s.length];
			this.a = a;
			this.colors = new int[s.length];
			this.used = new boolean[s.length];
			for (int i = 0; i < s.length; i++) {
				this.colors[i] = 0;
				this.points.add(s[i]);
			}
			Arrays.fill(this.used, false);
		}

		public void bfs(int i) {
			this.queue.add(i);
			while (!this.queue.isEmpty()) {
				i = this.queue.pop();
				out.print(points.get(i) + " ");
				this.used[i] = true;
				for (int j = 0; j < this.points.size(); j++) {
					if (this.a[i][j] == 1 && !this.queue.contains(j)
							&& !this.used[j]) {
						this.a[i][j] = 0;
						this.a[j][i] = 0;
						this.queue.addLast(j);
					}
				}
			}
		}

		public void dfs(int i) {
			this.colors[i] = 1;
			out.print(points.get(i) + " ");
			for (int j = 0; j < this.colors.length; j++) {
				if (this.a[i][j] == 1 && this.colors[j] == 0) {
					this.colors[j] = 1;
					this.a[i][j] = 0;
					this.a[j][i] = 0;
					dfs(j);
				} else if (this.a[i][j] == 1 && this.colors[j] == 1) {
					this.cycle = true;
					this.numberOfCycle++;
				}
			}
			this.colors[i] = 2;
		}
	}

	public class Time {

		int h;
		int min;
		int sec;

		public Time(String s) {
			String[] st = s.split(":");
			this.h = Integer.parseInt(st[0]);
			this.min = Integer.parseInt(st[1]);
			this.sec = (st[2] != null) ? Integer.parseInt(st[2]) : 0;
		}

		public String toString(int a) {
			String h = Integer.toString(this.h);
			String min = Integer.toString(this.min);
			String sec = Integer.toString(this.sec);
			if (h.length() == 1) {
				h = '0' + h;
			}
			if (min.length() == 1) {
				min = '0' + min;
			}
			if (sec.length() == 1) {
				sec = '0' + sec;
			}
			if (a == 5) {
				return h + ":" + min;
			} else {
				return h + ":" + min + ":" + sec;
			}
		}

		public void to12HoursFormat() {
			h %= 12;
		}

		public void add(int h, int min, int s) {
			this.sec += s;
			if (this.sec >= 60) {
				this.min++;
				this.sec %= 60;
			}
			this.min += min;
			if (this.min >= 60) {
				this.h++;
				this.min %= 60;
			}
			this.h += h;
			if (this.h >= 24) {
				this.h %= 24;
			}
		}
	}

	public int[] findPrimes(int x) {
		boolean[] erat = new boolean[x - 1];
		List<Integer> t = new ArrayList<Integer>();
		int l = 0, j = 0;
		for (int i = 2; i < x; i++) {
			if (erat[i - 2])
				continue;
			t.add(i);
			l++;
			j = i * 2;
			while (j < x) {
				erat[j - 2] = true;
				j += i;
			}
		}
		int[] primes = new int[l];
		Iterator<Integer> iterator = t.iterator();
		for (int i = 0; iterator.hasNext(); i++) {
			primes[i] = iterator.next().intValue();
		}
		return primes;
	}

	public double dist(pair a, pair b) {
		return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	}
	
	final int[] dx = {0, 1, 0, -1};
	final int[] dy = {-1, 0, 1, 0};
	
	int n, m;
	char[][] a;
	int[][] wx, wy;
	boolean[][] vis;

	public void solve() throws Exception {
		n = nextInt();
		m = nextInt();
		a = new char[n][];
		for (int i = 0; i < n; i++) {
			a[i] = nextString().toCharArray();
		}
		int sx = -1, sy = -1;
		loop: for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j] == 'S') {
					sx = i;
					sy = j;
					break loop;
				}
			}
		}
		wx = new int[n][m];
		wy = new int[n][m];
		vis = new boolean[n][m];
		if (dfs(sx, sy, 0, 0)) {
			out.println("Yes");
		} else {
			out.println("No");
		}
	}
	
	private boolean dfs(int x, int y, int shiftX, int shiftY) {
		if (vis[x][y]) {
			if (wx[x][y] != shiftX || wy[x][y] != shiftY) {
				return true;
			} else {
				return false;
			}
		}
		vis[x][y] = true;
		wx[x][y] = shiftX;
		wy[x][y] = shiftY;
		for (int k = 0; k < 4; k++) {
			int newX = x + dx[k];
			int newY = y + dy[k];
			int newShiftX = shiftX;
			int newShiftY = shiftY;
			if (newX >= n) { newX = 0; newShiftX++; }
			if (newY >= m) { newY = 0; newShiftY++; }
			if (newX < 0) { newX = n-1; newShiftX--; }
			if (newY < 0) { newY = m-1; newShiftY--; }
			if (a[newX][newY] != '#') {
				if (dfs(newX, newY, newShiftX, newShiftY)) {
					return true;
				}
			}
		}
		return false;
	}
}