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;
template <class T>
inline string DISPLAYBIT(T n, int s, int e) {
  string a;
  while (s >= e) {
    if (s < sizeof(n) * CHAR_BIT)
      ((sizeof(n) == 4) && (((n) & (1 << (s))) != 0)) ||
              ((sizeof(n) == 8) && (((n) & (((long long)(1)) << (s))) != 0))
          ? a += '1'
          : a += '0';
    s--;
  }
  return a;
}
template <class T>
inline int COUNTBIT(T n) {
  return (sizeof(n) == 4) ? __builtin_popcount(n) : __builin_popcountl(n);
}
template <class T>
inline int LSB(T n) {
  return (sizeof(n) == 4) ? __builtin_ffs(n) - 1 : __builtin_ffsl(n) - 1;
}
template <class T>
inline int MSB(T n) {
  return (sizeof(n) == 4) ? 31 - __builtin_clz(n) : 63 - __builtin_clzl(n);
}
template <class T>
inline T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (b == 0) ? a : GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / GCD(a, b));
}
template <class T>
inline T EUCLIDEAN(T a, T b, T& x, T& y) {
  if (a < 0) {
    T d = EUCLIDEAN(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = EUCLIDEAN(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = EUCLIDEAN(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <class T>
inline vector<pair<T, int> > FACTORISE(T n) {
  vector<pair<T, int> > R;
  for (T i = 2; n > 1;) {
    if (n % i == 0) {
      int C = 0;
      for (; n % i == 0; C++, n /= i)
        ;
      R.push_back(make_pair(i, C));
    }
    i++;
    if (i > n / i) i = n;
  }
  if (n > 1) R.push_back(make_pair(n, 1));
  return R;
}
template <class T>
inline vector<pair<int, int> > FACTORIZE(int n) {
  if (n > 1e7) return FACTORISE(n);
  vector<pair<int, int> > R;
  vector<int> a(({
    int b = ceil(sqrt(n));
    vector<int> d(n, 0);
    vector<int> e;
    int f = 2;
    e.push_back(2);
    e.push_back(3);
    for (int x = 1; x < b + 1; x++) {
      for (int y = 1; y < b + 1; y++) {
        int n = (4 * x * x) + (y * y);
        if (n <= n && (n % 12 == 1 || n % 12 == 5)) {
          d[n] ^= 1;
        }
        n = (3 * x * x) + (y * y);
        if (n <= n && n % 12 == 7) {
          d[n] ^= 1;
        }
        n = (3 * x * x) - (y * y);
        if (x > y && n <= n && n % 12 == 11) {
          d[n] ^= 1;
        }
      }
    }
    for (int r = 5; r < b + 1; r++) {
      if (d[r]) {
        for (int i = r * r; i < n; i += (r * r)) {
          d[i] = 0;
        }
      }
    }
    for (int c = 5; c < n; c++) {
      if (d[c]) {
        e.push_back(c);
      }
    }
    e;
  }));
  int i;
  if (a[({
        int z = (lower_bound((a).begin(), (a).end(), n) - (a).begin());
        (z == 0 && a[0] != n) ? -1 : z;
      })] == n) {
    R.push_back(make_pair(n, 1));
    return R;
  }
  int b = (int)sqrt(n);
  for (i = 0; a[i] <= b; i++) {
    if (n % a[i] == 0) {
      int d = 0;
      for (; n % a[i] == 0; d++, n /= a[i])
        ;
      R.push_back(make_pair(a[i], d));
    }
  }
  for (; a[i] < n; i++) {
    if (n % a[i] == 0) {
      R.push_back(make_pair(a[i], 1));
      break;
    }
  }
  return R;
}
template <class T>
inline bool IZPRIME(T n) {
  if (n <= 1) return false;
  for (T i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
template <class T>
inline bool ISPRIME(T n) {
  if (n > 1e7) return IZPRIME(n);
  vector<int> a(({
    int b = ceil(sqrt(n));
    vector<int> d(n, 0);
    vector<int> e;
    int f = 2;
    e.push_back(2);
    e.push_back(3);
    for (int x = 1; x < b + 1; x++) {
      for (int y = 1; y < b + 1; y++) {
        int n = (4 * x * x) + (y * y);
        if (n <= n && (n % 12 == 1 || n % 12 == 5)) {
          d[n] ^= 1;
        }
        n = (3 * x * x) + (y * y);
        if (n <= n && n % 12 == 7) {
          d[n] ^= 1;
        }
        n = (3 * x * x) - (y * y);
        if (x > y && n <= n && n % 12 == 11) {
          d[n] ^= 1;
        }
      }
    }
    for (int r = 5; r < b + 1; r++) {
      if (d[r]) {
        for (int i = r * r; i < n; i += (r * r)) {
          d[i] = 0;
        }
      }
    }
    for (int c = 5; c < n; c++) {
      if (d[c]) {
        e.push_back(c);
      }
    }
    e;
  }));
  int b = ({
    int z = (lower_bound((a).begin(), (a).end(), n) - (a).begin());
    (z == 0 && a[0] != n) ? -1 : z;
  });
  return (b != -1 && a[b] == n);
}
template <class T>
inline T TOTIENT(T n) {
  vector<pair<T, int> > R = FACTORIZE(n);
  T r = n;
  for (int i = 0; i < R.size(); i++) r = r / R[i].first * (R[i].first - 1);
  return r;
}
template <class T>
inline T CHECKMOD(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
inline T MULTIPLYMOD(T a, T b, T m) {
  return (
      T)((((long long)(a) * (long long)(b) % (long long)(m)) + (long long)(m)) %
         (long long)(m));
}
template <class T>
inline T DIVIDEMOD(T a, T b, T m) {
  T x, y;
  EUCLIDEAN(b, m, x, y);
  return MULTIPLYMOD(a, x, m);
}
template <class T>
inline T POWERMOD(T p, int e, T m) {
  if (e == 0)
    return 1 % m;
  else if (e % 2 == 0) {
    T t = POWERMOD(p, e / 2, m);
    return MULTIPLYMOD(t, t, m);
  } else
    return MULTIPLYMOD(POWERMOD(p, e - 1, m), p, m);
}
template <class T>
inline void SHOWMATRIX(vector<vector<T> >& A) {
  for (int i = 0; i < ((int)(A).size()); i++) {
    for (int j = 0; j < ((int)(A[0]).size()); j++) cout << A[i][j] << " ";
    cout << endl;
  }
}
template <class T>
inline void COPYMATRIX(int m, int n, vector<vector<T> >& A,
                       vector<vector<T> >& B) {
  B.clear();
  B.resize(n - m + 1, vector<T>(n - m + 1));
  for (int i = m, k = 0; i <= n; i++, k++) {
    for (int j = m, l = 0; j <= n; j++, l++) B[k][l] = A[i][j];
  }
}
template <class T>
inline void IDENTITYMATRIX(int n, vector<vector<T> >& A) {
  A.clear();
  A.resize(n, vector<T>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) A[i][j] = (i == j) ? 1 : 0;
}
template <class T, class BinaryOperation>
inline void CHECKMATRIX(vector<vector<T> > A, vector<vector<T> > B,
                        vector<vector<T> >& C, BinaryOperation b) {
  int n = ((int)(A).size());
  C.clear();
  C.resize(((int)(A).size()), vector<T>(((int)(A).size())));
  for (int i = 0; i < ((int)(A).size()); i++)
    for (int j = 0; j < ((int)(A[0]).size()); j++)
      C[i][j] = b(A[i][j], B[i][j]);
}
template <class T>
inline void mulMatrix(vector<vector<T> > A, vector<vector<T> > B,
                      vector<vector<T> >& C) {
  C.clear();
  C.resize(((int)(A).size()), vector<T>(((int)(B[0]).size())));
  for (int i = 0; i < ((int)(A).size()); i++)
    for (int j = 0; j < ((int)(B[0]).size()); j++)
      for (int k = 0; k < ((int)(B).size()); k++) C[i][j] += A[i][k] * B[k][j];
}
template <class T>
inline void TRANSMATRIX(vector<vector<T> >& B, vector<vector<T> >& A) {
  B.clear();
  B.resize(((int)(A[0]).size()), vector<T>(((int)(A).size())));
  for (int i = 0; i < ((int)(B).size()); i++) {
    for (int j = 0; j < ((int)(B[0]).size()); j++) B[i][j] = A[j][i];
  }
}
template <class T, class BinaryOperation>
inline void SCALARMATRIX(vector<vector<T> >& B, vector<vector<T> >& A, T c,
                         BinaryOperation d) {
  B.clear();
  B.resize(((int)(A[0]).size()), vector<T>(((int)(A).size())));
  for (int i = 0; i < ((int)(B).size()); i++) {
    for (int j = 0; j < ((int)(B[0]).size()); j++) B[i][j] = d(A[j][i], c);
  }
}
template <class T>
inline string TOSTRING(T n) {
  ostringstream ost;
  ost << n;
  ost.flush();
  return ost.str();
}
template <class T>
inline void TOVAR(string s, T& r) {
  istringstream sin(s);
  sin >> r;
}
template <class T>
inline void STOV(string s, vector<T>& vi) {
  vi.clear();
  istringstream sin(s);
  for (T v; sin >> v; vi.push_bakc(v))
    ;
}
template <class T>
inline void VTOS(vector<T> vi, string& s) {
  ostringstream sout;
  for (int i = 0; i < vi.size(); i++) {
    if (i > 0) sout << ' ';
    sout << vi[i];
  }
  s = sout.str();
}
template <class T>
inline vector<T> ATOV(T a[]) {
  vector<T> v(a, a + sizeof(a) / sizeof(T));
  return v;
}
template <class T>
struct Fraction {
  T a, b;
  Fraction(T a = 0, T b = 1);
  string toString();
};
template <class T>
Fraction<T>::Fraction(T a, T b) {
  T d = GCD(a, b);
  a /= d;
  b /= d;
  if (b < 0) a = -a, b = -b;
  this->a = a;
  this->b = b;
}
template <class T>
string Fraction<T>::toString() {
  ostringstream sout;
  sout << a << "/" << b;
  return sout.str();
}
template <class T>
Fraction<T> operator+(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b + q.a * p.b, p.b * q.b);
}
template <class T>
Fraction<T> operator-(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b - q.a * p.b, p.b * q.b);
}
template <class T>
Fraction<T> operator*(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.a, p.b * q.b);
}
template <class T>
Fraction<T> operator/(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b, p.b * q.a);
}
int n, m, start_x, start_y;
vector<string> G;
vector<vector<pair<int, int> > > chk;
vector<vector<bool> > vis;
struct elem {
  int x, y, maze_x, maze_y;
};
int main() {
  double tmp_start = clock();
  fprintf(stderr, "Start\n");
  n = ({
    int x;
    scanf("%d", &x);
    x;
  }),
  m = ({
    int x;
    scanf("%d", &x);
    x;
  });
  G.clear();
  vis.resize(n, vector<bool>(m, 0));
  chk.resize(n, vector<pair<int, int> >(m, make_pair((int)1e9, (int)1e9)));
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    for (int j = 0; j < ((int)(temp).size()); j++)
      if (temp[j] == 'S') {
        start_x = i;
        start_y = j;
      }
    G.push_back(temp);
  }
  pair<int, int> dir[4] = {make_pair(-1, 0), make_pair(1, 0), make_pair(0, 1),
                           make_pair(0, -1)};
  bool ans = 0;
  stack<elem> Q;
  elem start;
  start.x = start_x, start.y = start_y, start.maze_x = 0, start.maze_y = 0;
  Q.push(start);
  vis[start_x][start_y] = 1;
  chk[start_x][start_y] = make_pair(start.maze_x, start.maze_y);
  while (!Q.empty()) {
    elem S = Q.top();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int x = S.x + dir[i].first;
      int y = S.y + dir[i].second;
      int maze_x = S.maze_x, maze_y = S.maze_y;
      if (x < 0) {
        x = n - 1;
        maze_x--;
      }
      if (y < 0) {
        y = m - 1;
        maze_y--;
      }
      if (x >= n) {
        x = 0;
        maze_x++;
      }
      if (y >= m) {
        y = 0;
        maze_y++;
      }
      if (G[x][y] == '#') continue;
      if (vis[x][y]) {
        if (chk[x][y] != make_pair(maze_x, maze_y)) {
          ans = true;
          break;
        }
      } else {
        elem t = {x, y, maze_x, maze_y};
        vis[x][y] = 1;
        chk[x][y] = make_pair(maze_x, maze_y);
        Q.push(t);
      }
    }
    if (ans) break;
  }
  if (ans)
    cout << "Yes\n";
  else
    cout << "No\n";
  fprintf(stderr, "Total time = %.2lf sec\n",
          (double)(clock() - tmp_start) / CLOCKS_PER_SEC);
  return 0;
}
