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.
#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
char mmap[N][N];
bool vis[N][N];
pair<int, int> record[N][N];
int n, m;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};
struct Node {
  int x, y;
  Node(int x, int y) : x(x), y(y) {}
};
bool bfs(int x, int y) {
  queue<Node> q;
  q.push(Node(x, y));
  while (!q.empty()) {
    Node cur = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int __x = cur.x + dx[i];
      int __y = cur.y + dy[i];
      int _x = (__x % n + n) % n;
      int _y = (__y % m + m) % m;
      if (mmap[_x][_y] == '#') continue;
      if (vis[_x][_y]) {
        if (record[_x][_y].first != __x || record[_x][_y].second != __y)
          return true;
      } else {
        vis[_x][_y] = true;
        record[_x][_y] = make_pair(__x, __y);
        q.push(Node(__x, __y));
      }
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mmap[i]);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mmap[i][j] == 'S') {
        x = i, y = j;
        goto end;
      }
end:
  puts(bfs(x, y) ? "Yes" : "No");
  return 0;
}
