#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int MAX = 1550, oo = INT_MIN;
pair<int, int> vis[MAX][MAX];
int n, m, dir[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
char mm[MAX][MAX];
bool hhfind = 0;
void dfs(int i, int j) {
  if (hhfind) return;
  int ti = (i % n + n) % n, tj = (j % m + m) % m;
  if (vis[ti][tj].first == oo)
    vis[ti][tj] = pair<int, int>(i, j);
  else if (vis[ti][tj] != pair<int, int>(i, j)) {
    hhfind = 1;
    return;
  } else
    return;
  for (int d = 0; d < 4; d++) {
    int ni = i + dir[d][0], nj = j + dir[d][1];
    int tni = (ni % n + n) % n, tnj = (nj % m + m) % m;
    if (mm[tni][tnj] == '.' || mm[tni][tnj] == 'S') {
      dfs(ni, nj);
    }
  }
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", mm[i]);
  }
  int si, sj;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mm[i][j] == 'S') {
        si = i, sj = j;
        break;
      }
    }
  }
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      vis[i][j].first = vis[i][j].second = oo;
    }
  }
  hhfind = 0;
  dfs(si, sj);
  if (hhfind)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
