#include <bits/stdc++.h>
using namespace std;
const int N = 1500 + 10;
int n, m;
int st[N][N][3];
char a[N][N];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
bool dfs(long long sx, long long sy, long long ex, long long ey) {
  if (st[sx][sy][2] == 1 && (st[sx][sy][0] != ex || st[sx][sy][1] != ey))
    return true;
  if (st[sx][sy][2] == 0) {
    st[sx][sy][0] = ex;
    st[sx][sy][1] = ey;
    st[sx][sy][2] = 1;
  } else {
    return false;
  }
  for (int i = 0; i < 4; i++) {
    long long x = (sx + dx[i] + n) % n;
    long long y = (sy + dy[i] + m) % m;
    if (a[x][y] != '#') {
      if (dfs(x, y, ex + dx[i], ey + dy[i])) return true;
    }
  }
  return false;
}
int main() {
  memset(st, 0, sizeof(st));
  int sx, sy;
  scanf("%d%d", &n, &m);
  sx = sy = -1;
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
    for (int j = 0; sx + sy == -2 && j < m; j++) {
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  }
  if (dfs(sx, sy, sx, sy))
    puts("Yes");
  else
    puts("No");
}
