#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-7;
const long long maxint = 2147483647;
const long long minint = -2147483648;
using namespace std;
long long MIN(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long MAX(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power(long long a, long long p) {
  if (p == 0) return 1;
  if (p & 1) {
    return a * power(a, p - 1);
  } else {
    long long c = power(a, p / 2);
    return c * c;
  }
}
long long sq(long long x) { return x * x; }
char grid[1510][1510];
char done[1510][1510];
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int row, col;
bool pos = false;
struct coor {
  int x, y;
} memo[1510][1510];
bool bfs(int si, int sj) {
  memo[si][sj].x = si;
  memo[si][sj].y = sj;
  queue<int> q;
  q.push(si);
  q.push(sj);
  grid[si][sj] = '*';
  int i, ti, tj, ai, aj;
  while (!q.empty()) {
    si = q.front();
    q.pop();
    sj = q.front();
    q.pop();
    ai = si % row;
    if (ai < 0) ai += row;
    aj = sj % col;
    if (aj < 0) aj += col;
    if (done[ai][aj] == 1) continue;
    for (i = 0; i < 4; i++) {
      ti = si + dir[i][0];
      tj = sj + dir[i][1];
      ai = ti % row;
      if (ai < 0) ai += row;
      aj = tj % col;
      if (aj < 0) aj += col;
      if (memo[ai][aj].x == ti && memo[ai][aj].y == tj) continue;
      if (grid[ai][aj] == '#') continue;
      if (grid[ai][aj] == '*') return true;
      grid[ai][aj] = '*';
      memo[ai][aj].x = ti;
      memo[ai][aj].y = tj;
      q.push(ti);
      q.push(tj);
    }
    ai = si % row;
    if (ai < 0) ai += row;
    aj = sj % col;
    if (aj < 0) aj += col;
    done[ai][aj] = 1;
  }
  return false;
}
int main() {
  memset(memo, -1, sizeof memo);
  scanf("%d %d", &row, &col);
  int i;
  for (i = 0; i < row; i++) {
    scanf("%s", &grid[i][0]);
  }
  int j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      if (grid[i][j] == 'S') {
        grid[i][j] = '.';
        pos = bfs(i, j);
        break;
      }
    }
  }
  if (pos)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
