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.math.BigInteger;
import java.util.*;

public class Task {

    public static void main(String[] args) throws IOException {
        //new Task().solve();

        new Thread(null, new Runnable() {

            @Override
            public void run() {
                try {
                    new Task().solve();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 28).start();
    }

    int mod = 1000000007;

    PrintWriter out;

    int n;
    int m;

    int inf = 2000000000;

    ArrayList<Integer>[] g;

    void solve() throws IOException {

        Reader in;

        try {

            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }

        //BufferedReader br = new BufferedReader( new FileReader("in.txt") );
        //BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

        n = in.nextInt();
        m = in.nextInt();

        int sx = 0;
        int sy = 0;

        for (int i = 0; i < n; i++) {

            String s = in.nextLine();
            for (int j = 0; j < m; j++) {

                a[i][j] = s.charAt(j);
                if (a[i][j] == 'S') {
                    sx = i;
                    sy = j;
                }
            }
        }

        if (dfs(sx, sy, -1000000, -1000000))
            out.println("Yes");
        else
            out.println("No");

        out.flush();
        out.close();
    }

    int[][] a = new int[1500][1500];
    boolean[][] used = new boolean[1500][1500];
    int[][] f = new int[1500][1500];

    int[] dx = {1, -1, 0, 0};
    int[] dy = {0, 0, 1, -1};

    boolean dfs(int x, int y, int px, int py) {

        int nx = (x%n+n)%n;
        int ny = (y%m+m)%m;

        if (!used[nx][ny]) {
            used[nx][ny] = true;
            f[nx][ny] = h(x,y);
        }
        else {

            if (f[nx][ny] != h(x,y))
                return true;
            return false;
        }

        for (int i = 0; i < 4; i++) {
            nx = ((x+dx[i])%n+n)%n;
            ny = ((y+dy[i])%m+m)%m;
            if (a[nx][ny] != '#')
                if (dfs(x+dx[i], y+dy[i], x, y))
                    return true;
        }

        return false;
    }

    int h(int x, int y) {
        return x*10000+y;
    }

    class Edge { int v, u; int w, c; Edge(int v, int u, int w, int c) { this.v = v; this.u = u; this.w = w; this.c = c; } }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a < p.a)
                return 1;

            if (a > p.a)
                return -1;

            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}