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.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.AbstractCollection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Siddharth
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public int n, m;
    public int modulo(int number, int base) {
        int mod = number%base;
        while (mod < 0) mod += base;
        return mod;
    }

    public ArrayList<Pair> neighbors(String[] grid, Pair node) {
        ArrayList<Pair> validNeighbors = new ArrayList<Pair>();
        if (grid[modulo(node.first, n)].charAt(modulo(node.second-1, m)) != '#')
            validNeighbors.add(new Pair(node.first, node.second-1));
        if (grid[modulo(node.first, n)].charAt(modulo(node.second+1, m)) != '#')
            validNeighbors.add(new Pair(node.first, node.second+1));
        if (grid[modulo(node.first-1, n)].charAt(modulo(node.second, m)) != '#')
            validNeighbors.add(new Pair(node.first-1, node.second));
        if (grid[modulo(node.first+1 ,n)].charAt(modulo(node.second, m)) != '#')
            validNeighbors.add(new Pair(node.first+1, node.second));
        return validNeighbors;
    }

    public boolean bfs(String[] grid, Pair[][] gridPairs, boolean[][] gridVisits, Pair start) {
        PriorityQueue<Pair> que = new PriorityQueue<Pair>();
        que.add(start);
        gridVisits[start.first][start.second] = true;
        gridPairs[start.first][start.second] = start;
        while (!que.isEmpty()) {
            Pair nodeToVisit = que.poll();
            ArrayList<Pair> neighbors = neighbors(grid, nodeToVisit);
            //System.out.ptintln(neighbors.size());
            for (Pair el : neighbors) {
                int first = modulo(el.first, n);
                int second = modulo(el.second, m);
                //System.out.ptintln(first+", "+second);
                if (gridVisits[first][second] == false)  {
                    //System.out.ptintln("el: "+el);
                    que.add(el);
                    gridVisits[first][second] = true;
                    gridPairs[first][second] = el;
                }
                else {
                    //System.out.ptintln("In check - "+ gridPairs[first][second]+", "+el);
                    if ((modulo(gridPairs[first][second].first,n) == modulo(el.first,n) &&
                            modulo(gridPairs[first][second].second, m) == modulo(el.second, m))
                            && !(gridPairs[first][second].first == el.first &&
                            gridPairs[first][second].second == el.second))  {
                        return true;
                    }
                }
            }
            //System.out.ptintln(que);
        }
        return false;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        Pair start = new Pair(-1, -1);
        String[] grid = new String[n];

        for (int i = 0; i < n; i++) {
            grid[i] = in.nextString();
            int index = grid[i].indexOf('S');
            if (index != -1)
                start = new Pair(i, index);
        }
        //System.out.ptintln("Start: "+start);
        //for (int i = 0; i < n; i++)
        //System.out.ptintln(grid[i]);
        Pair gridPairs[][] = new Pair[n][m];
        for (int i = 0; i < n; i++)
            Arrays.fill(gridPairs[i], new Pair(-1, -1));
        boolean gridVisits[][] = new boolean[n][m];
        boolean infinite = bfs(grid, gridPairs, gridVisits, start);
        if (infinite)
            out.println("Yes");
        else
            out.println("No");
    }
}

class Pair implements  Comparable {
    int first;
    int second;
    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

    public String toString() {
        return "("+first+", "+second+")";
    }

    public int compareTo(Object o) {
        return 0;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String nextString() {
        StringBuilder ans = new StringBuilder();
        int c = read();
        while(isSpaceChar(c))
            c = read();
        while(!isSpaceChar(c)) { ans.append((char)c); c = read(); }
        return ans.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void println(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}

